Repository Forums Support WooCommerce Extended Coupon Features PRO How to use weight as a condition Reply To: How to use weight as a condition

#10904
Heidi Maskelyne
Participant

try this below add it to your functions.php

change the $coupon_id to coupon you created

add_action('woocommerce_applied_coupon', 'remove_coupon_from_cart');

function remove_coupon_from_cart( ) {

    global $woocommerce;
    
    $coupon_id = 'MYCOUPON';

    $min_order= 75;
    $max_weight = 10;
    
    $cart_weight =$woocommerce->cart->cart_contents_weight;
    $cart_total = $woocommerce->cart->get_cart_total();
    
    if ($cart_weight > $max_weight || $cart_total < $min_order){
	    $woocommerce->cart->remove_coupon( $coupon_id );
    }