问题
I would like to disable requirement to select shipping method for a particular product type (here "booking" product type) on the checkout. So they should be able to buy product without shipping method.
回答1:
To disable shipping completely* when a specific product type is in cart you will use the following:
add_filter( 'woocommerce_cart_needs_shipping', 'filter_cart_needs_shipping_callback' );
function filter_cart_needs_shipping_callback( $needs_shipping ){
foreach ( WC()->cart->get_cart() as $item ) {
if ( $item['data']->is_type('booking') ) {
$needs_shipping = false;
break;
}
}
return $needs_shipping;
}
Code goes in function.php file of your active child theme (or active theme). Tested and works.
* Shipping methods and shipping checkout fields too.
来源:https://stackoverflow.com/questions/57639470/how-to-disable-shipping-completely-for-a-woocommerce-product-type