I tried to use different codes to hide shipping method from Woocommerce cart page. The codes work until I delete a product from the cart. Once I delete a product the shipping section returns. After I refresh the page its work again.
One of the codes I tried:
add_filter( 'woocommerce_cart_needs_shipping', 'filter_cart_needs_shipping' );
function filter_cart_needs_shipping( $needs_shipping ) {
if ( is_cart() ) {
$needs_shipping = false;
}
return $needs_shipping;
}
I tried this code also:
function disable_shipping_calc_on_cart( $show_shipping ) {
if( is_cart() ) {
return false;
}
return $show_shipping;
}
add_filter( 'woocommerce_cart_ready_to_calc_shipping', 'disable_shipping_calc_on_cart', 99 );
I put the code in my theme function.php file. The problem is the same for both codes.
I use WordPress 6.5.2, WooCommerce 8.8.3 and Twenty Twenty-Four theme.
How can this problem be solved?
sheepcloud is a new contributor to this site. Take care in asking for clarification, commenting, and answering.
Check out our Code of Conduct.