How to disable shipping completely for a WooCommerce product type?

混江龙づ霸主 提交于 2020-01-02 07:02:39

问题


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

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!