The Foxy forums are on the move!

We're in the process of moving our forums over to a new system, and so these forums are now read-only.
If you have a question about your store in the meantime, please don't hesitate to reach out to us via email.

How to add a free gift with order

Hey guys, I've got a fun one for you!

I have a client who wants to be able to give away a t-shirts as a free gift with orders. The fun sticking point is asking the customer for a t-shirt size. They also want this to be an easy win for their customers, so not adding a product with a size and then applying a coupon to get it for free - it's too much work for a gift.

I've found an example on a makeup website where they have what I would consider an ideal solution, I'm just not sure if this is possible in FoxyCart. Here's a link to a product that currently has a free gift in the example site: http://www.ulta.com/ulta/browse/productDetail.jsp?skuId=2300708&productId=xlsImpprod13741151

Here are screenshots of how the functionality works:

From the cart screen, the product has a dropdown to select your free gift.
image

This only has one option here, but for my client, they'd ask for t-shirt size.
image

When the selection is made, it's added as a new free product.
image

..so, how would we do that? :D
Comments
  • fc_adamfc_adam FoxyCart Team
    @TiffaniH,

    Great question - and it would definitely be possible with a combination of Twig and javascript on the templates.

    There is an existing snippet here: https://wiki.foxycart.com/v/2.0/snippets/donation_on_checkout - which adds the ability to add a donation to the cart from the checkout. You could use that snippet as a basis and change it to instead add a tshirt to the cart, and instead of the text input have a shirt size dropdown. You could also expand on the HTML to only show it if the tshirt isn't already present in the cart.

    You could also take this same approach and include it directly into the cart if you wanted to include it there. You'd edit the "cart include" template to add in the additional logic you need.
  • Thanks @fc_adam - That's awesome! I've got a couple of questions:

    Is there a way to link the custom field to particular products? I'm assuming there's a way to loop through the products in the cart and check for a given product code for example? (thinking ahead for where they'll take this next)

    It looks like all the settings for this are going to need to be handled through the FC admin panel. Would there be any way to pass the information about the custom field through from the api or something? The icing on the cake would be if I could write up a script so that the client can turn the 'free gift' field on / off and tweak the settings without having to dig into the code, which they won't do. That would make my day!

  • fc_adamfc_adam FoxyCart Team
    edited May 2016
    @TiffaniH,

    Good questions.
    Is there a way to link the custom field to particular products? I'm assuming there's a way to loop through the products in the cart and check for a given product code for example? (thinking ahead for where they'll take this next)
    You can certainly loop through products in Twig - so you could set the custom fields to only output if certain products are present, and other products aren't present. Within Twig a product loop looks like this:
    {% for item in items %}
    {% if item.category == "my-category" %}
    // do something
    {% endif %}
    {% endfor %}
    It looks like all the settings for this are going to need to be handled through the FC admin panel. Would there be any way to pass the information about the custom field through from the api or something? The icing on the cake would be if I could write up a script so that the client can turn the 'free gift' field on / off and tweak the settings without having to dig into the code, which they won't do. That would make my day!
    We do have a configuration option for "Set your own custom values". It's just a straight text area where you can include a JSON object with custom values you want to include on the checkout. You could include some settings there that your client could then change. It'd still technically be code - but more easily edited than within the template itself.

    You could also set up some javascript on the website that on page load sets a custom session attribute to flag if the custom product should be allowed or not - and what product codes it's allowed for. You can then check against those within the Twig. If you set it through javascript on every page load, you could set it based on a configuration within the CMS on the site if you can create custom settings panels within that.
  • thanks @fc_adam

    Can the 'Set your own custom values' be updated via the api? That would be awesomely helpful.

  • fc_adamfc_adam FoxyCart Team
    @TiffaniH,

    Using our new Hypermedia API you can change that configuration value, but not with our legacy API. Information on our new API at https://api.foxycart.com
Sign In or Register to comment.