Ready to get started?Download WordPress


Woocommerce check if coupon is applied (2 posts)

  1. Blindacme
    Posted 9 months ago #

    Anyone know how I can check if a coupon has been applied to the Woocommerce checkout so that I can do something if it is?

    This is what I have but it does not seem to work, however if I remove the === $coupon_id from the if statement it works but does so for ALL coupons and not the specific coupon I am checking for.

    add_action('woocommerce_before_cart_table', 'apply_product_on_coupon');
    function apply_product_on_coupon( ) {
        global $woocommerce;
    	$coupon_id = '12345';
    		if( $woocommerce->cart->applied_coupons === $coupon_id ) {
    		echo 'YAY it works';

    Thanks for your help :)

  2. rahyrs
    Posted 4 months ago #

    Where does this code go?
    Can I use it in the review-order.php or checkout.php to check if the visitor has apply a coupon or not. If has, then he can proceed to place order. If not, a notice to say he must fill in coupon code.

    Actually I want to make the coupon field mandatory/required, but I don't know how to do it and don't know which field to change.

    Thank you


You must log in to post.

About this Topic