Loading...

How To Automatically Apply A Coupon Code To An Order

Emilian F. Published on 05 September, 2014

You should always take the opportunity to make the checkout process smoother for your customers. The smoother the process, the more sales you make! This modification does that by automatically adding a coupon code to an order using a specific URL. This makes it easier to run promotions since your customers only have to click on a link to receive their discount as opposed to filling out a form and entering the coupon code manually.

Follow the instructions below to install the modification.

Instructions

  1. Login to your control panel and navigate to Design -> Theme Files/Edit HTML & CSS and open the Panels/SideCouponCodeBox.html file.

  2. Add the following code to the bottom of the file after the last </div> tag:

    
    <script type="text/javascript">
        $(document).ready(function() {
            function getQueryVariable(parameter) {
                var searchString = window.location.search.substring(1);
                var params = searchString.split('&');
                for (var i = 0; i < params.length; i++) {
                    var pair = params[i].split('=');
                    if (decodeURIComponent(pair[0]) == parameter) {
                        return decodeURIComponent(pair[1]);
                    }
                }
            }
    
            var couponCode = getQueryVariable('coupon');
    
            if(couponCode) {
                $("#couponcode").val(couponCode);
                $("#SideCouponCodeBox form input[type='image']").trigger('click');
            }
        });
    
    </script>
    
    
  3. Save the changes to the file.

How It Works

To automatically apply the coupon code to the order you will need to pass a parameter called coupon to the cart.php file. The URL should look like this: http://www.your-store.com/cart.php?coupon=COUPON-CODE-HERE

You have to replace COUPON-CODE-HERE with your own coupon code. The script will take the coupon code from the URL parameter, fill in the coupon field and then automatically submit the form to the cart.

Troubleshooting

If you need help installing the modification or need to make some changes to it then contact us. We'll be happy to help.

Emilian F. Published on 05 September, 2014