WooCommerce Apply Coupon With A Checkbox On The Product Page


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.

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.
WooCommerce Conversion Rate Optimisation (CRO) eBook
100 WooCommerce Conversion Rate Optimisation Tips

Leave a Reply

If you are going to write code in the comments, please wrap it between code tags.

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

Other Recent Guides

Subscribe To Emails

Get exclusive WooCommerce tips that I only share with email subscribers

Join hundreds of other subscribers