如何完全禁用WooCommerce产品类型的运输? [英] How to disable shipping completely for a WooCommerce product type?
本文介绍了如何完全禁用WooCommerce产品类型的运输?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!
问题描述
我想禁止在结帐时为特定产品类型(此处为预订"产品类型)选择运输方式的要求.因此,他们应该能够在没有运输方式的情况下购买产品.
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.
推荐答案
当购物车中有特定产品类型时,要完全禁用运输*,您将使用以下内容:
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;
}
代码进入您的活动子主题(或活动主题)的function.php文件中.经过测试,可以正常工作.
Code goes in function.php file of your active child theme (or active theme). Tested and works.
*运送方式以及运送结帐字段.
这篇关于如何完全禁用WooCommerce产品类型的运输?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!
查看全文