【发布时间】:2021-10-05 13:20:54
【问题描述】:
我基于之前的 SO 帖子,但在我的情况下,无论购物车中有什么,“运送到其他地址”部分都会消失。
我有一个虚拟产品,当您将它添加到购物车时,它就在购物车中:
-
收货地区不显示。
-
如果购物车中有任何其他产品,包括其他产品。因为您现在正在运送产品,所以会出现 Ship to。
我使用的代码是:
add_filter( 'woocommerce_cart_needs_shipping_address', 'disable_checkout_shipping_address');
function disable_checkout_shipping_address( $needs_shipping_address ) {
$products_ids = [3649];
$found = false;
$others_found = false;
foreach ( WC()->cart->get_cart() as $cart_item ){
if (in_array( $cart_item['data']->get_id(), $products_ids ) ){
$found = true;
} else {
$others_found = true;
}
}
if( $found && ! $others_found )
$needs_shipping_address = true;
return $needs_shipping_address;
}
有什么建议吗?
【问题讨论】:
标签: php wordpress woocommerce checkout