Skip to Content

Shopify – Auto fill discount code on checkout page

By tmbr

Locate this line of code in your cart.liquid template
[php]

[/php]

Directly below that line of code you need to place something like this
[php][/php]

Where “RESELLERDISCOUNTCODE” is your discount code.

If you want apply this to only a specific group of customers. you can use tags to create a customer group and then only apply the code to customers who are in that group.

[php]
{% if customer.tags contains ‘RESELLER’ %}

{% endif %}
[/php]

Add coupon code from URL

This will allow you to add a coupon code to any URL and auto populate that coupon code at checkout.

Example URL – https://myshopifystore.com?coupon=MYCOUPONCODE
you can add coupon=MYCOUPONCODE to any URL on your store

Locate this line of code in your cart.liquid template
[php]

[/php]

Directly below that line of code you need to place something like this
[php][/php]

Make sure you are including jquery and Jquery cookie in your theme. Your theme probably already has jquery so you would just need to include jquery-cookie

Jquery: https://jquery.com/
jquery-cookie: https://github.com/carhartl/jquery-cookie

This Gist should be a solid building block to customize for your specific needs and should be added at the end of your layout.theme file before your tag and within a script tag
[php]