mirror of
https://gh.wpcy.net/https://github.com/mainwp/Code-Snippets-Functions.git
synced 2026-04-29 11:32:21 +08:00
https://stackoverflow.com/questions/74975472/hide-shipping-methods-if-a-virtual-product-is-in-the-cart
12 lines
459 B
Text
12 lines
459 B
Text
add_filter( 'woocommerce_cart_needs_shipping', 'remove_virtual_product_shipping_methods' );
|
|
function remove_virtual_product_shipping_methods( $needs_shipping ){
|
|
//Loop trough cart items
|
|
foreach ( WC()->cart->get_cart() as $item ) {
|
|
//If a product in cart is a vritual product remove all shipping
|
|
if ( $item['data']->is_virtual() ) {
|
|
$needs_shipping = false;
|
|
break;
|
|
}
|
|
}
|
|
return $needs_shipping;
|
|
}
|