Flash sale: Get up to 30% off themes and extensions. Ends April 26 at 3 pm UTC. Shop the sale.
  1. Documentation /
  2. Smart Coupons /
  3. URL coupons – how to auto-apply single or multiple coupons codes via a link

URL coupons – how to auto-apply single or multiple coupons codes via a link

Smart Coupons provides a powerful, “all-in-one” solution for gift cards, store credits, discount coupons, and vouchers extending the core functionality of WooCommerce coupons.

This doc article explains how using Smart Coupons plugin, you can add a unique coupon code(s) to the URL. When a user clicks on that URL, the coupon(s) gets automatically applied and (optionally) add products to the customer’s shopping cart.

You can also add the coupon code to any custom URL on your site and allow the discount to get automatically applied on click of that URL.

This is a very useful feature. Your users don’t have to type & apply the coupons manually. Instead, they just have to click on the provided link. No coupon code hassles, easy sharing.

Apply a single coupon via a link (Coupon URL)

↑ Back to top
  1. Go to your WordPress admin panel. Under Marketing > Coupons, click on Add coupon. You can also modify your existing coupon.
  2. Set the discount type, coupon amount, expiry, set usage limit and restrictions and other settings as per your requirements. Publish / Update the coupon.
  3. Under ‘Coupon shareable link’, you’ll find a button ‘Click to copy’.
  4. Click on the button to copy the link & share it via email, social media, deal sites, etc. You can also find the shareable coupon code link on the Coupons dashboard. Here’s how
  5. Once any user clicks on that URL, the coupon gets auto-applied.

For example, your website URL is https://www.fashionworld.com/. Then you can embed a coupon code to the URL like this – https://www.fashionworld.com/?coupon-code=specialsale10&sc-page=shop.

Apply multiple coupons via a link (Coupon URL)

↑ Back to top

You can also add multiple coupon codes to the URL and apply multiple coupons via that single URL. Pass a comma-separated list of coupons in the link as shown – https://www.fashionworld.com/product/trendingwatch/?coupon-code=specialsale10,holiday15,exclusivedisc5&sc-page=shop

Note – For more than five coupon codes in the URL, only the first five coupons will be auto-applied. To apply more than five coupons via URL, Smart Coupons plugin provides a hook for custom coding.

Check the following sample code about how you can use the hook to increase the limit to 10. If you want to know about the best way to add a custom code to your website refer to this document: Customizing WooCommerce: Best Practices

/**
 * Function to modify the number of coupons allowed to be applied from a URL
 * 
 * @author StoreApps (https://www.storeapps.org/)
 *
 * @param integer $limit The limit.
 * @return integer
 */
function storeapps_wc_sc_max_url_coupons_limit( $limit = 5 ) {
    $limit = 10;
    return $limit;
}
function storeapps_handle_smart_coupons_hooks() {
    add_filter( 'wc_sc_max_url_coupons_limit', 'storeapps_wc_sc_max_url_coupons_limit', 11 );
}
add_action( 'wp_loaded', 'storeapps_handle_smart_coupons_hooks' );

Redirect to a page after coupon is applied

↑ Back to top

Smart Coupons provides a URL param ‘sc-page’ for redirecting users to a page after the coupons get applied via URL. By default, the user gets redirected to the shop page. Following is the list of possible values that you can use as ‘sc-page’.

WooCommerce predefined pages

↑ Back to top

If you want to use pages that are defined by the WooCommerce you can use either ‘shop’, ‘cart’, ‘checkout’ or ‘my-account’

If the target page is the ‘shop’ page then the link will be like:

https://www.fashionworld.com/?coupon-code=specialsale10&sc-page=shop

Page ID

↑ Back to top

You can also use the numeric page id of the target page.

If the page id of the target page is 123 then the link will be like:

https://www.fashionworld.com/?coupon-code=holiday15&sc-page=123

Page path

↑ Back to top

You can also use the path of the target page with respect to the website.

If the target page is https://www.fashionworld.com/landing-page/ then the link will be like:

https://www.fashionworld.com/?coupon-code=exclusivedisc5&sc-page=landing-page