How to prevent free shipping and discount codes from applying simultaneously?

Hi
We are currently using Hextom Free Shipping Bar. The app is set up so if your basket value is above £40 shipping will be free. However, should your basket value be £50 (example) and you enter a discount code taking your basket value down to £45 you still receive free shipping and the 10% discount code.

We only wish to offer free shipping once above £40 or a discount code (discount code is set for any basket value), and not offer both. Does anybody have a solution where one of the options is available and not both.

We’ve spoken to the APP developers and they’ve informed us it’s a Shopify issue
Thanks
Satnam

Hello @satnam123

It is possible to create a custom script that would override the default behavior of the Hextom Free Shipping Bar app. You can create a script that checks if the discount code has been applied and if it has, then disable the free shipping option. This way, customers can only receive either the free shipping or the discount code, but not both.

To create a script, you can go to your Shopify admin dashboard and navigate to Settings > Checkout > Additional scripts. From there, you can add a new script and paste in your custom code.

Here’s an example code that you can use as a starting point:

(function(){
  var discountCode = null;
  var freeShippingEnabled = false;

  function applyFreeShipping() {
    // check if cart value is above £40
    if (Shopify.checkout.total_price > 4000) {
      // enable free shipping
      freeShippingEnabled = true;
      // show free shipping message
      // replace this with the code for the Hextom Free Shipping Bar app
    }
  }

  function applyDiscountCode() {
    // check if discount code has been applied
    if (discountCode !== null) {
      // show discount code message
      // replace this with the code for the discount code app
      // disable free shipping
      freeShippingEnabled = false;
    }
  }

  // listen for discount code changes
  document.addEventListener('onDiscountCodeApplied', function(event) {
    discountCode = event.detail.discount_code;
    applyDiscountCode();
  });

  // check for free shipping on page load
  applyFreeShipping();

  // listen for cart changes
  document.addEventListener('onCartUpdated', function(event) {
    // check for free shipping
    applyFreeShipping();
    // check for discount code
    applyDiscountCode();
  });
})();

Please note that this is just an example code and would require some modifications to work with your specific setup. It’s also recommended to test the script thoroughly before implementing it on your live store.

Thank you for coming back to me

Would you be available to carry out the work? happy to pay for your service

Would the above solution only be available in shopify plus?