我最近设置了我的分层运输,我读了this tutorial关于这一点,我修改了他的代码,我这样:
add_filter( 'woocommerce_package_rates', 'bbloomer_woocommerce_tiered_shipping', 10, 2 );
function bbloomer_woocommerce_tiered_shipping( $rates, $package ) {
$thresholdsmall = 200;
$thresholdbig = 899.99;
if ( WC()->cart->subtotal < $thresholdsmall ) {
if ( isset( $rates['free_shipping:4'] ) ) unset( $rates['free_shipping:18'] );
if ( isset( $rates['free_shipping:14'] ) ) unset( $rates['free_shipping:19'] );
if ( isset( $rates['free_shipping:14'] ) ) unset( $rates['free_shipping:21'] ) ;
if ( isset( $rates['flat_rate:9'] ) ) unset( $rates['flat_rate:23'] );
if ( isset( $rates['flat_rate:15'] ) ) unset( $rates['flat_rate:24'] );
if ( isset( $rates['flat_rate:16'] ) ) unset( $rates['flat_rate:26'] );
if ( isset( $rates['flat_rate:16'] ) ) unset( $rates['flat_rate:22'] );
if ( isset( $rates['flat_rate:16'] ) ) unset( $rates['flat_rate:25'] );
}
if ( WC()->cart->subtotal > $thresholdbig ) {
( isset( $rates['free_shipping:19'] ) ) ;
( isset( $rates['free_shipping:21'] ) ) ;
unset( $rates['free_shipping:18'] );
unset( $rates['free_shipping:14'] );
unset( $rates['free_shipping:4'] );
( isset( $rates['flat_rate:25'] ) ) ;
( isset( $rates['flat_rate:26'] ) ) ;
unset( $rates['flat_rate:22'] );
unset( $rates['flat_rate:23'] );
unset( $rates['flat_rate:24'] );
unset( $rates['flat_rate:9'] );
unset( $rates['flat_rate:15'] );
unset( $rates['flat_rate:16'] );
}
else {
( isset( $rates['free_shipping:4'] ) ) ;
( isset( $rates['free_shipping:18'] ) ) ;
unset( $rates['free_shipping:19'] );
unset( $rates['free_shipping:21'] );
unset( $rates['free_shipping:14'] );
( isset( $rates['flat_rate:9'] ) ) ;
( isset( $rates['flat_rate:24'] ) ) ;
( isset( $rates['flat_rate:23'] ) ) ;
( isset( $rates['flat_rate:22'] ) ) ;
unset( $rates['flat_rate:15'] );
unset( $rates['flat_rate:16'] );
unset( $rates['flat_rate:25'] );
unset( $rates['flat_rate:26'] );
}
return $rates;
}
现在,当我的购物车低于200,只有免费送货:4和统一费率:9显示。
我应该修改什么以包括免费送货:14,统一费率:15,统一费率:16?
编辑:为了更清楚地说明这一点,我试图做一个3层航运。购物车总额低于200,购物车总额超过200但低于900,购物车总额超过900。不同的费率对应于不同的航运选项/公司。x1c 0d1x
以下是不同的运费参考
·200以下的推车
- Fedex Ground (Free) => free_shipping:14
- Fedex 2 days ($20) => flat_rate:15
- Fedex Stand Overnight ($45) => flat_rate:16
·900以下的推车
- USPS Priority (free) => free_shipping:4
- USPS Express ($45) => flat_rate:9
- Fedex 2 days AM ($20) => flat_rate:22
- Fedex Stand Overnight ($40) => flat_rate:23
- Fedex Pty. Overnight ($50) => flat_rate:24
·推车在200和(低于)900之间
- Fedex Stand 2 days (Free) => free_shipping:18
·推车高达900
- USPS Express (free) => free_shipping:19
- Fedex Stand. Overnight (Free) => free_shipping:21
- Fedex Pty. Overnight ($20) => flat_rate:25
- Fedex Pty. Saturday Deliv. ($40) => flat_rate:26
1条答案
按热度按时间b1uwtaje1#
在这里,我试图设置所有这些复杂的运费系统在这个代码,因为有很多错误和错误的代码。我已经尽我所能的代码注解。
下面是代码:
这个代码应该可以...