【发布时间】:2019-05-13 08:10:19
【问题描述】:
首先,对不起我的英语。
我有一个名为 Big Materials 的运输类,什么时候是 10 欧元固定加 2 欧元每件。我已使用此代码将最高运费设置为 24 欧元。
当我将 8 件放入购物车时,运费为 26 欧元。当我把 9 件装到购物车时,运费是 28 欧元,当我把 10 件装到购物车时,运费是我设置的 24 欧元。
我不知道,问题出在哪里。
是在纳税还是……?
你能帮帮我吗?
谢谢。
/**
* Function to set a minimum/cap on the shipping rates.
*/
function my_minimum_limit_shipping_rates_function( $rates, $package ) {
$methods = WC()->shipping()->get_shipping_methods();
$shipping_limit = 24; // The maximum amount would be $24
// Loop through all rates
foreach ( $rates as $rate_id => $rate ) {
// Check if the rate is higher then a certain amount
if ( $rate->cost > $shipping_limit ) {
$rate->cost = $shipping_limit;
// Recalculate shipping taxes
if ( $method = $methods[ $rate->get_method_id() ] ) {
$taxes = WC_Tax::calc_shipping_tax( $rate->cost, WC_Tax::get_shipping_tax_rates() );
$rate->set_taxes( $method->is_taxable() ? $taxes : array() );
}
}
}
return $rates;
}
add_filter( 'woocommerce_package_rates', 'my_minimum_limit_shipping_rates_function', 10, 2 );
【问题讨论】: