Posted on

WooCommerce – How to Redirect to Any Page on Click of a Coupon?

Last updated on April 9, 2021

What if I say, you could redirect users to a specific landing page on click of the coupon sent in the email? This will nudge visitors to buy the product quickly.

Now, the default WooCommerce doesn’t provide any functionality to redirect users on coupon click. But the official and best-selling WooCommerce coupons plugin, Smart Coupons do allow it.

With Smart Coupons, you can also bulk generate coupons, create gift cards, allow coupons for subscription renewals, restrict coupons based on payment methods, location…and do much other stuff.

This article will help you with the steps on how to redirect users directly to any page on click of a coupon in WooCommerce received via email.

Why store owners need to redirect users to a landing page?

Many WooCommerce store owners run discounts to attract customers. They also want existing customers to buy their popular products.

So, they send a coupon via email (bulk generate and send coupons) or send gift card / store credit via email that can be redeemed only on that product.

Now, when a user clicks on the coupon, the user gets redirected to the shop page.

But as a store owner, your intention will always be to provide a good experience by allowing users to redirect on a specific landing page – product page, product category page, special offers page or any custom page.

By doing so, customer’s attention is focused on that particular page and with the coupon as bait, they simply check out quickly.

Smart Coupons allows you to redirect users to a particular landing page with the click of the coupon using a simple code.

Let’s understand this with an example. In this example, we are setting a product page, on which the coupon is applicable, as the landing page. So, the customer who will receive the coupon in email & when he will click on the coupon, he’ll be redirected to that product page on which this coupon is applicable.

Steps to redirect customers to a product page

  • Open file ‘functions.php’ of your website’s child theme for editing
  • Copy & paste the following code at the end of that file. In the following example, we are setting the redirect URL as the product page URL on which this coupon will be applicable. If you want to set some other URL as the target URL then you should make sure that the target URL is set as $permalink in the following code
    /**
     * Function to change coupon url as per the product restricted in the coupon
     * 
     * @author StoreApps 
     *
     * @param array $coupon_target Current URL.
     * @param mixed $coupon The coupon object.
     * @return string
     */
    function storeapps_sc_coupon_url_in_email( $coupon_target = '', $coupon = null ) {
    	$coupon_code = ( is_object( $coupon ) && is_callable( array( $coupon, 'get_code' ) ) ) ? $coupon->get_code() : '';
    	$product_ids = ( is_object( $coupon ) && is_callable( array( $coupon, 'get_product_ids' ) ) ) ? $coupon->get_product_ids() : array();
    	if ( ! empty( $product_ids ) && ! empty( $coupon_code ) ) {
    		$product_id = current( $product_ids );
    		$product    = wc_get_product( $product_id );
    		$permalink  = ( is_object( $product ) && is_callable( array( $product, 'get_permalink' ) ) ) ? $product->get_permalink() : '';
    		if ( ! empty( $permalink ) ) {
    			$coupon_target = add_query_arg( array( 'coupon-code' => $coupon_code ), $permalink );
    		}
    	}
    	return $coupon_target;
    }
    add_filter( 'sc_coupon_url_in_email', 'storeapps_sc_coupon_url_in_email', 99, 2 );
    
  • Save the file

That’s all.

Now, your customers will directly be taken to the product page when they click on the coupon.

How beneficial is this step as a WooCommerce store owner?

This will not only bring in sales but also make your brand stand out for providing a smooth checkout experience.

Smart Coupons plugin has many more features to help grow sales and cater to your customers more effectively and uniquely.

Get Smart Coupons plugin now

Leave a Reply

Your email address will not be published. Required fields are marked *

This site uses Akismet to reduce spam. Learn how your comment data is processed.