Coupon

Hi everyone

I am trying to make a coupon which enables people to buy one product X and get product Y for free. How should the code look like? Somebody can help me with it please

Maya
Tagged:
Comments
  • fc_adamfc_adam FoxyCart Team
    @mayaober,

    Good question. Our coupons don't currently support the ability to add a product when it is added to the cart - but it is something we're considering for the future.

    For now - it is possible to achieve with some custom javascript on your store, and we can help you with how that would work. Could I confirm with you your desired set up - the customer needs to add both product X and the coupon, and once both are present (in any order), product Y should be added to the cart automatically. Is that right?

    If they remove either the coupon or product X - should product Y be automatically removed? Or alternatively if the coupon is a 100% off discount for product Y - if they remove product X, should it instead just remove the coupon, so product Y is no longer discounted by the coupon?
  • I don't know if an answer was ever provided but I need to do something similar. In my case I want to add a free product to the cart if the value of goods purchased is £30 or more. I also want that free product removed if the customer edits their basket and the resultant value drops below £30.
    Thanks.
    Graham.
  • fc_marijafc_marija FoxyCart Team
    edited November 17
    Hi @grahamlinter -

    This should be doable with some custom JavaScript on the configuration page. This page gives guidance on adding items to the cart: https://wiki.foxycart.com/v/2.0/json#making_a_jsonp_call_to_the_cart

    If you add

    {% if context == 'cart' or context == 'checkout' %}
    <script>
    FC.client.request('https://'+FC.settings.storedomain+'/cart?name=My+Product&price=20');
    </script>
    {% endif %}
    into your custom footer text area in the Configuration page of your FoxyCart admin, it'll add a product to the cart.

    You'll just need the JavaScript that gets the order total (this example removes any discounts from the order total):

    var eligible_amount = FC.json.total_item_price + FC.json.total_discount;


    And remove the item by changing the quantity to zero if it's been added and the order total has changed using the FC.client.request() as above.

    You can use the events on this page: https://wiki.foxycart.com/v/2.0/javascript to run the script when the cart changes.

    Hopefully that will help you get started. If you need additional help writing the script, let us know.
  • Thanks fc_marija - I will give that a try next week and let you know how it goes.
Sign In or Register to comment.