Woocommerce数量范围出货价格



我需要像这样设置运输价格:

1 - 5个数量,60美元$90的数量为6 - 10

我该怎么做?因此,如果有人从产品中购买3件,那么运费为60,如果购买6件或更多,则为90。

woocommerce提供的基本[qty]占位符不能做到这一点,并且没有找到任何可以做到的插件。

也许是这样的?在您的活动主题functions.php文件

中添加以下函数
add_filter( 'woocommerce_package_rates', 'custom_shipping_costs', 20, 2 );
function custom_shipping_costs( $rates, $package ) {
global $woocommerce;
$qty =  $woocommerce->cart->cart_contents_count;
//error_log($qty);
foreach( $rates as $rate_key => $rate ){
// Excluding free shipping methods
if( $rate->method_id != 'free_shipping'){
// Between 1 and 5
if($qty > 0 && $qty <= 5):
$rates[$rate_key]->cost = '60';
// Between 6 and 10
elseif($qty > 5 && $qty <= 10):
$rates[$rate_key]->cost = '90';
else:
// For over 10
$rates[$rate_key]->cost = '60';
endif;
}
}
return $rates;
}

最新更新