Product Page

WooCommerce Apply Coupon With A Checkbox On The Product Page

WooCommerce Apply Coupon With A Checkbox On The Product Page

Pre-Requisites

You must have already created the coupon code and entered in the code snippet.

How To Implement This Solution?

Simply copy the pre-coded solution to your active theme’s functions.php or preferably the Code Snippets Plugin.

About This Solution

This is a bit of a weird one but there’s some interesting marketing psychology to it…

Amazon allow customers to apply a coupon by checking a box on the product page.

WooCommerce Apply Coupon With A Checkbox On The Product Page

Why not just automatically give the customer the discount though?

Amazon’s tactic to display a coupon option, instead of just automatically showing a discounted price, gives shoppers an extra incentive to make the purchase right away.

This kind of psychology is explained more in the WooCommerce Conversion Rate Optimisation (CRO) eBook.

Back to this snippet, when implementing this code, customers will be able to apply the coupon to their order when the box is checked and the product is added to their cart.

Don’t forget to first create your coupon and second replace my example one in the code.

/**
 * Snippet Name:	WooCommerce Apply Coupon With A Checkbox On The Product Page
 * Snippet Author:	ecommercehints.com
 */

add_action( 'woocommerce_after_add_to_cart_button', 'ecommercehints_coupon_checbox', 10 );
function ecommercehints_coupon_checbox() {
    echo '<p><label><input type="checkbox" name="apply_coupon" value="1"/> Apply a coupon by checking this box!</label></p>';
}

// Apply coupon when checkbox is checked
add_action( 'woocommerce_add_to_cart', 'ecommercehints_apply_coupon_on_checkbox_check', 10, 6 );
function ecommercehints_apply_coupon_on_checkbox_check( $cart_item_key, $product_id, $quantity, $variation_id, $variation, $cart_item_data ) {
    if ( isset( $_POST['apply_coupon'] ) && $_POST['apply_coupon'] == 1 ) {
        $coupon_code = 'YOUR_COUPON_CODE_HERE'; // Replace with your coupon code
        $coupon = new WC_Coupon( $coupon_code );
        WC()->cart->apply_coupon( $coupon_code );
    }
}

Snippet Benefits

  • Leverage eCommerce psychology to get users to buy more quickly.

100 WooCommerce Conversion Rate Optimisation Tips

This field is for validation purposes and should be left unchanged.

Let’s collaborate!

Need to outsource WordPress development?

Join forces with UnlimitedWP for an outsourced white label web development service you can truly rely on.

First Timer Here?

Sign up to receive 10% off on your first month with us.

26027
WELCOME OFFER