0
votes

How can I exclude shipping charges from cart page? Meaning it should include only on checkout page.

I am new to woocommerce and I do not have much knowledge about that. In my project, I do not want to include Shipping charges on cart page. I tried this

add_filter( 'woocommerce_cart_needs_shipping', '__return_false' );

But it hides shipping (charges + address) from the whole project until I remove the code.

1
It means, shipping charges will be included on the checkout page, right?Maha Dev
Yes. Shipping charges should be include only on checkout page.Tanmay Vats

1 Answers

0
votes

You have to unset other shipping methods on cart page like this :

//functions.php

add_filter( 'woocommerce_package_rates','hide_shipping_when_free_is_available', 10, 2 );

function hide_shipping_when_free_is_available( $rates, $package ) {

    // Check if it is cart page
    if (is_cart() ) {

        // To unset a single rate/method, do the following. This example unsets flat_rate shipping
        unset( $rates['flat_rate'] );

        // To unset all methods except for free_shipping, do the following
        $free_shipping          = $rates['free_shipping'];
        $rates                  = array();
        $rates['free_shipping'] = $free_shipping;
    }

    return $rates;
}

You can unset other shipping methods if you used like this :

unset( $rates['flat_rate'] );