具有多种运费选项和价格的分层运输
Tiered Shipping with multiple Shipping rates options and prices
我最近设置了分层运输,我阅读了 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 时,只有 free_shipping:4 和 flat_rate:9 显示。
我应该修改什么以包含 free_shipping:14,flat_rate:15,flat_rate:16?
编辑:为了使这一点更清楚,我尝试进行 3 层运输。购物车总数少于 200,购物车总数超过 200 但少于 900,以及购物车总数超过 900。
不同的费率对应不同的运费options/companies。
这里有不同的运费参考
• 购物车低于 200
- Fedex Ground (Free) => free_shipping:14
- Fedex 2 days () => flat_rate:15
- Fedex Stand Overnight () => flat_rate:16
• 购物车低于 900
- USPS Priority (free) => free_shipping:4
- USPS Express () => flat_rate:9
- Fedex 2 days AM () => flat_rate:22
- Fedex Stand Overnight () => flat_rate:23
- Fedex Pty. Overnight () => 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 () => flat_rate:25
- Fedex Pty. Saturday Deliv. () => flat_rate:26
在这里,我尝试在此代码中设置所有这些复杂的运费系统,因为您的代码中存在很多错误和错误。我已经尽我所能评论了代码。
代码如下:
add_filter( 'woocommerce_package_rates', 'shipping_rates_based_on_cart_amount', 10, 2 );
function shipping_rates_based_on_cart_amount( $rates, $package ) {
if ( WC()->cart->subtotal < 900 ) { ## Under 900
unset( $rates['free_shipping:19'] ); // remove: USPS Express (free)
unset( $rates['free_shipping:21'] ); // remove: Fedex Stand. Overnight (Free)
unset( $rates['flat_rate:25'] ); // remove: Fedex Pty. Overnight ()
unset( $rates['flat_rate:26'] ); // remove: Fedex Pty. Saturday Deliv. ()
if ( WC()->cart->subtotal < 200 ) { ## Under 200
// For => "Fedex Stand Overnight ()"
if ( isset( $rates['flat_rate:16'] ) )
{
unset( $rates['flat_rate:23'] ); // remove: Fedex Stand Overnight ()
unset( $rates['flat_rate:24'] ); // remove: Fedex Pty. Overnight ()
}
// For => "Fedex 2 days () "
if ( isset( $rates['flat_rate:15'] ) )
unset( $rates['flat_rate:22'] ); // remove: Fedex 2 days AM ()
} else { ## Between 200 and under 900
// For => "Fedex Stand 2 days (free)"
if ( isset( $rates['free_shipping:18'] ) )
{
unset( $rates['free_shipping:14'] ); // Fedex Ground (Free)
unset( $rates['flat_rate:15'] ); // remove: Fedex 2 days ()
}
// For => "Fedex Stand Overnight ()"
if ( isset( $rates['flat_rate:23'] ) )
unset( $rates['flat_rate:16'] ); // remove: Fedex Stand Overnight ()
}
} else { ## From 900 (up to 900)
## 1) FEDEX
// For => "Fedex Stand. Overnight (Free)"
if ( isset( $rates['free_shipping:21'] ) )
{
unset( $rates['free_shipping:18'] ); // remove: Fedex Stand 2 days (Free)
unset( $rates['free_shipping:14'] ); // remove: Fedex Ground (Free)
}
// For => "Fedex Pty. Overnight ()"
// Or for => "Fedex Pty. Saturday Deliv. ()"
if ( isset( $rates['flat_rate:25'] ) || isset( $rates['flat_rate:26'] ) )
{
unset( $rates['flat_rate:15'] ); // remove: Fedex 2 days ()
unset( $rates['flat_rate:22'] ); // remove: Fedex 2 days AM (
unset( $rates['flat_rate:16'] ); // remove: Fedex Stand Overnight ()
unset( $rates['flat_rate:23'] ); // remove: Fedex Stand Overnight ()
unset( $rates['flat_rate:24'] ); // remove: Fedex Pty. Overnight ()
unset( $rates['flat_rate:9'] ); // remove: USPS Express ()
}
## 2) USPS
if ( isset( $rates['free_shipping:19'] ) ) // For => "USPS Express (free)"
unset( $rates['free_shipping:4'] ); // remove: USPS Priority (free)
}
return $rates;
}
这段代码应该可以工作……
You will need to refresh shipping cached data: disable, save and enable, save related shipping methods for the current shipping zone, in woocommerce shipping settings.
我最近设置了分层运输,我阅读了 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 时,只有 free_shipping:4 和 flat_rate:9 显示。
我应该修改什么以包含 free_shipping:14,flat_rate:15,flat_rate:16?
编辑:为了使这一点更清楚,我尝试进行 3 层运输。购物车总数少于 200,购物车总数超过 200 但少于 900,以及购物车总数超过 900。
不同的费率对应不同的运费options/companies。
这里有不同的运费参考
• 购物车低于 200
- Fedex Ground (Free) => free_shipping:14
- Fedex 2 days () => flat_rate:15
- Fedex Stand Overnight () => flat_rate:16
• 购物车低于 900
- USPS Priority (free) => free_shipping:4
- USPS Express () => flat_rate:9
- Fedex 2 days AM () => flat_rate:22
- Fedex Stand Overnight () => flat_rate:23
- Fedex Pty. Overnight () => 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 () => flat_rate:25
- Fedex Pty. Saturday Deliv. () => flat_rate:26
在这里,我尝试在此代码中设置所有这些复杂的运费系统,因为您的代码中存在很多错误和错误。我已经尽我所能评论了代码。
代码如下:
add_filter( 'woocommerce_package_rates', 'shipping_rates_based_on_cart_amount', 10, 2 );
function shipping_rates_based_on_cart_amount( $rates, $package ) {
if ( WC()->cart->subtotal < 900 ) { ## Under 900
unset( $rates['free_shipping:19'] ); // remove: USPS Express (free)
unset( $rates['free_shipping:21'] ); // remove: Fedex Stand. Overnight (Free)
unset( $rates['flat_rate:25'] ); // remove: Fedex Pty. Overnight ()
unset( $rates['flat_rate:26'] ); // remove: Fedex Pty. Saturday Deliv. ()
if ( WC()->cart->subtotal < 200 ) { ## Under 200
// For => "Fedex Stand Overnight ()"
if ( isset( $rates['flat_rate:16'] ) )
{
unset( $rates['flat_rate:23'] ); // remove: Fedex Stand Overnight ()
unset( $rates['flat_rate:24'] ); // remove: Fedex Pty. Overnight ()
}
// For => "Fedex 2 days () "
if ( isset( $rates['flat_rate:15'] ) )
unset( $rates['flat_rate:22'] ); // remove: Fedex 2 days AM ()
} else { ## Between 200 and under 900
// For => "Fedex Stand 2 days (free)"
if ( isset( $rates['free_shipping:18'] ) )
{
unset( $rates['free_shipping:14'] ); // Fedex Ground (Free)
unset( $rates['flat_rate:15'] ); // remove: Fedex 2 days ()
}
// For => "Fedex Stand Overnight ()"
if ( isset( $rates['flat_rate:23'] ) )
unset( $rates['flat_rate:16'] ); // remove: Fedex Stand Overnight ()
}
} else { ## From 900 (up to 900)
## 1) FEDEX
// For => "Fedex Stand. Overnight (Free)"
if ( isset( $rates['free_shipping:21'] ) )
{
unset( $rates['free_shipping:18'] ); // remove: Fedex Stand 2 days (Free)
unset( $rates['free_shipping:14'] ); // remove: Fedex Ground (Free)
}
// For => "Fedex Pty. Overnight ()"
// Or for => "Fedex Pty. Saturday Deliv. ()"
if ( isset( $rates['flat_rate:25'] ) || isset( $rates['flat_rate:26'] ) )
{
unset( $rates['flat_rate:15'] ); // remove: Fedex 2 days ()
unset( $rates['flat_rate:22'] ); // remove: Fedex 2 days AM (
unset( $rates['flat_rate:16'] ); // remove: Fedex Stand Overnight ()
unset( $rates['flat_rate:23'] ); // remove: Fedex Stand Overnight ()
unset( $rates['flat_rate:24'] ); // remove: Fedex Pty. Overnight ()
unset( $rates['flat_rate:9'] ); // remove: USPS Express ()
}
## 2) USPS
if ( isset( $rates['free_shipping:19'] ) ) // For => "USPS Express (free)"
unset( $rates['free_shipping:4'] ); // remove: USPS Priority (free)
}
return $rates;
}
这段代码应该可以工作……
You will need to refresh shipping cached data: disable, save and enable, save related shipping methods for the current shipping zone, in woocommerce shipping settings.