【发布时间】:2020-05-08 10:48:55
【问题描述】:
我一直在寻找一种有条件地禁用两种送货方式的方法
- 表率
- 距离率
基于项目数。
商品数量不是指数量,而是指购物车中有多少种不同的产品。 IE 购物车中的 2 个灯和 3 个桌子的项目数为 2,总数量为 5。
我还想确保此规则仅对特定类别有效。
我试过了:
function hide_shipping_count_based( $rates, $package ) {
// Set count variable
$cart_count = 0;
// Calculate cart's total
foreach( WC()->cart->cart_contents as $key => $value) {
$cart_count ++;
}
// only if the weight is over 150lbs find / remove specific carrier
if( $cart_count > 2 ) {
// loop through all of the available rates
unset( $rates[ 'distance_rate' ] );
unset( $rates[ 'table_rate' ] );
}
return $rates;
}
add_filter( 'woocommerce_package_rates', 'hide_shipping_count_based', 10, 2 );
【问题讨论】:
标签: php wordpress woocommerce hook-woocommerce shipping-method