Home Forums WoodMart support forum Hide Free Shipping if Other Shipping Class is available

Hide Free Shipping if Other Shipping Class is available

Viewing 3 posts - 1 through 3 (of 3 total)
  • Author
    Posts
  • #104664

    Soko
    Participant

    Hello,

    We would like to hide Free Shipping if other Shipping Class is available.

    Thank you,

    Attachments:
    You must be logged in to view attached files.
    #104673

    newsprince
    Participant

    @Soko

    Add this snippet to functions.php file on child theme or on a snippet plugin

    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;
    }
    add_filter( 'woocommerce_package_rates', 'my_hide_shipping_when_free_is_available', 100 );
    #104674

    Soko
    Participant

    @newsprince

    Thank you so much

Viewing 3 posts - 1 through 3 (of 3 total)