• Hello

    Two days ago I asked on this subject, I got an excellent answer.
    Now I have continued question and nobody sees it, So I open a new subject.

    To my first question, I got the code added to functions.php

    add_filter( 'woocommerce_package_rates', 'my_hide_shipping_when_free_is_available', 100 );
    
    function my_hide_shipping_when_free_is_available( $rates ) {
    	$free = array();
    	foreach ( $rates as $rate_id => $rate ) {
    		if ( 'free_shipping' === $rate->method_id ) {
    			$free[ $rate_id ] = $rate;
    			break;
    		}
    	}
    	return ! empty( $free ) ? $free : $rates;
    }

    It works well, Thanks.

    ————————–

    The continued question:

    I would like to add also the Local Pickup.

    The problem is that when the invitation is greater than the Minimum Order Amount The Local Pickup gone.

    Should be:
    From under the Minimum Order Amount – fixed amount + Local Pickup
    From about the Minimum Order Amount – Free Shipping + Local Pickup

    How do I add this condition to this function?

    (If you do not understand me, you can look in the original conversation)

    Thanks

Viewing 2 replies - 1 through 2 (of 2 total)
  • Hello,

    you didn’t mentioned the “Local pickup” in your first inquiry. However, i think I got something for you. Try this:

    add_filter( 'woocommerce_package_rates', 'my_hide_shipping_when_free_is_available', 100 );
    function my_hide_shipping_when_free_is_available( $rates ) {
    	$free = array();
    	$pickup = array();
    	foreach ( $rates as $rate_id => $rate ) {
    		if ( 'free_shipping' === $rate->method_id ) {
    			$free[ $rate_id ] = $rate;
    			// break;
    		}
    		if ( 'local_pickup' === $rate->method_id ) {
    			$pickup[ $rate_id ] = $rate;
    			// break;
    		}
    
    	}
    	if( ! empty( $free ) ){
    		$rates = $free;
    		if ( ! empty( $pickup ) ) {
    			$rates = array_merge( $rates, $pickup );
    		}
    	}
    	return $rates;
    }
    

    Replace the first snippet completely with this one!

    Thread Starter healiny

    (@healiny)

    Hello
    I didn’t mentioned the “Local pickup” because that came later.

    It works great ??
    Thank you very much.

Viewing 2 replies - 1 through 2 (of 2 total)
  • The topic ‘Setting Free Shipping with Minimum Order Amount – 2’ is closed to new replies.