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

Topic Resolution: Resolved
Viewing 5 posts - 1 through 5 (of 5 total)
  • Author
    Posts
  • #10806
    Diane Milano
    Participant

    I have my shipping set up using weight to determine shipping price. I need to have my coupon recognize a minimum dollar amount AND a maximum weight for the coupon to be valid, and to automatically remove if either or both of the conditions move out of range once the coupon is applied. I am trying to get a minimum dollar amount of $75.00 and a weight range between 0.0 lbs and 10 lbs. 10 lbs being the max weight. I would also like to have a notice telling the customer that the coupon has become invalid if either or both conditions move out of range once the coupon is applied. I can get the minimum price of $75.00 using the minimum spend in the restriction. I have tried using the custom fields in the restriction section for the weight but am not having any success. Any help would be greatly appreciated. I am new to this.

    Thanks
    Dee

    #10826
    Soft79
    Keymaster

    Maximum weight of all products in the cart would require custom code.

    Maximum weight of a product can be achieved using the custom field, e.g.: _weight “< 10" You can set a custom error message on the miscellaneous-tab.

    #10834
    Diane Milano
    Participant

    Where can I get the code from? Is it something that can easily be done? Where does it get placed?

    Dee

    #10874
    Soft79
    Keymaster

    You need to hire a developer for that.

    #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 );
        }
Viewing 5 posts - 1 through 5 (of 5 total)
  • You must be logged in to reply to this topic.