我一直在寻找一种有条件地禁用两种运输方式的方法
表率
距离率
基于项目计数。
我所说的项目计数不是指数量,而是指购物车中有多少种不同的产品。IE 2 Lamps and 3 tables in the cart would be an item count of 2 and a combined quantity of 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 );
回首忆惘然