具有多种运输价格选项和价格的分层运输 [英] Tiered Shipping with multiple Shipping rates options and prices

查看:67
本文介绍了具有多种运输价格选项和价格的分层运输的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我最近设置了分层运输,并阅读了



以下是不同的运费参考



•购物车在200美元以下

 -Fedex Ground(免费)=> free_shipping:14 
-Fedex 2 days($ 20)=> flat_rate:15
-联邦快递过夜($ 45)=> flat_rate:16

•购物车在900以下

 -USPS优先级(免费)=> free_shipping:4 
-USPS Express($ 45)=> flat_rate:9
-Fedex 2天AM($ 20)=> flat_rate:22
-联邦快递过夜($ 40)=> flat_rate:23
-Fedex Pty。隔夜($ 50)=> flat_rate:24

•购物车介于200和(低于)900

 -Fedex Stand 2天(免费)=> free_shipping:18 

•购物车高达900

 -USPS Express(免费)=>免费送货:19 
-Fedex Stand。隔夜(免费)=> free_shipping:21
-Fedex Pty。Overnight($ 20)=> flat_rate:25
-Fedex Pty.Saturday Deliv。 ($ 40)=> flat_rate:26


解决方案

在这里,我尝试设置所有这些此代码中的运费费率系统非常复杂,因为您的代码中存在很多错误和错误。我已尽力注释了该代码。



这里是该代码:

  add_filter('woocommerce_package_rates','shipping_rates_based_on_cart_amount',10,2); 
函数shipping_rates_based_on_cart_amount($ rates,$ package){

if(WC()-> cart->小计< 900){##低于900

unset($ rates ['free_shipping:19']); //删除:USPS Express(免费)
unset($ rates [’free_shipping:21’]); //移除:Fedex Stand。隔夜(免费)
未设定($ rates [’flat_rate:25’]); //删除:Fedex Pty。隔夜($ 20)
unset($ rates [’flat_rate:26’]); //删除:Fedex Pty。Saturday Deliv。 ($ 40)

如果(WC()->购物车->小计< 200){##低于200

//用于=> 隔夜联邦快递站($ 45)
if(isset($ rates [’flat_rate:16’]))
{
unset($ rates [’flat_rate:23’]); //移除:联邦快递过夜($ 40)
unset($ rates [’flat_rate:24’]); // //移除:Fedex Pty。隔夜($ 50)
}

// For => Fedex 2天($ 20)
if(isset($ rates ['flat_rate:15']))
unset($ rates ['flat_rate:22']); //移除:Fedex 2天上午($ 20)

}否则{## 200至900以下

//对于=> Fedex Stand 2天(免费)
if(isset($ rates [’free_shipping:18’]))
{
unset($ rates [’free_shipping:14’]); // Fedex Ground(免费)
unset($ rates [’flat_rate:15’]); //删除:Fedex 2天($ 20)
}

//对于=> 隔夜联邦快递($ 40)
if(isset($ rates [’flat_rate:23’]))
unset($ rates [′flat_rate:16’]); //移除:联邦快递过夜($ 45)
}

} else {##从900(最多900)

## 1)FEDEX

//对于=> Fedex Stand。隔夜(免费)
if(isset($ rates [’free_shipping:21’]))
{
unset($ rates [’free_shipping:18’]); //删除:Fedex Stand 2天(免费)
unset($ rates [’free_shipping:14’]); //删除:Fedex Ground(免费)
}

//对于=> Fedex Pty。隔夜($ 20)
//或==> Fedex Pty。Saturday Deliv。($ 40)
if(isset($ rates ['flat_rate:25'])|| isset($ rates ['flat_rate:26']))
{
unset($ rates ['flat_rate:15']); //删除:Fedex 2天($ 20)
unset($ rates [’flat_rate:22’]); //移除:联邦快递2天上午($ 20
unset($ rates ['flat_rate:16']); //移除:联邦快递隔夜($ 45)
unset($ rates ['flat_rate:23 ']); //删除:联邦快递过夜($ 40)
unset($ rates ['flat_rate:24']); //删除:联邦快递过夜($ 50)
unset($ rates ['flat_rate:9']); //删除:USPS Express($ 45)
}

## 2)USPS

if(isset($ rates ['free_shipping:19']))//对于=> USPS Express(免费)
未设置($ rates [’free_shipping:4’]); //删除:USPS优先级(免费)

}

return $ rates;

}

此代码应该有效……


您将需要刷新运输缓存的数据:在woocommerce运输中禁用,保存和启用,保存当前运输区域的相关运输方法设置。



I recently set up my tiered shipping and I read this tutorial about this, I modified his code to mine like this:

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;
}

Right now when my cart is under 200, only free_shipping:4 and flat_rate:9 is showing.

What should I modify to include free_shipping:14,flat_rate:15,flat_rate:16?

Edit: To make this clearer I tried to make a 3 tiered shipping. Cart total that is less than 200, cart total that is more than 200 but less than 900, and cart total more than 900. The different rates correspond to the different shipping options/companies.

Here are the different shipping rates references

• CART UNDER 200

- Fedex Ground (Free)       => free_shipping:14
- Fedex 2 days ($20)        => flat_rate:15
- Fedex Stand Overnight ($45)   => flat_rate:16

• CART UNDER 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

• CART BETWEEN 200 and (under) 900

- Fedex Stand 2 days (Free) =>  free_shipping:18

• CART UP TO 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

解决方案

Here I have tried to set all this complicated shipping rates system in this code, as there is a lot of errors and mistakes in your code. I have commented the code the best I can.

Here is that code:

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 ($20)
            unset( $rates['flat_rate:26'] ); // remove: Fedex Pty. Saturday Deliv. ($40)

        if ( WC()->cart->subtotal < 200 ) { ## Under 200

            // For => "Fedex Stand Overnight ($45)"
            if ( isset( $rates['flat_rate:16'] ) )
            {
                unset( $rates['flat_rate:23'] ); // remove: Fedex Stand Overnight ($40)
                unset( $rates['flat_rate:24'] ); // remove: Fedex Pty. Overnight ($50)
            }

            // For => "Fedex 2 days ($20) "
            if ( isset( $rates['flat_rate:15'] ) )
                unset( $rates['flat_rate:22'] ); // remove: Fedex 2 days AM ($20)

        } 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 ($20)
            }

            // For => "Fedex Stand Overnight ($40)"
            if ( isset( $rates['flat_rate:23'] ) )
                unset( $rates['flat_rate:16'] ); // remove: Fedex Stand Overnight ($45)
        }

    } 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 ($20)"
        // Or for => "Fedex Pty. Saturday Deliv. ($40)"
        if ( isset( $rates['flat_rate:25'] ) || isset( $rates['flat_rate:26'] ) )
        {
            unset( $rates['flat_rate:15'] ); // remove: Fedex 2 days ($20)
            unset( $rates['flat_rate:22'] ); // remove: Fedex 2 days AM ($20
            unset( $rates['flat_rate:16'] ); // remove: Fedex Stand Overnight ($45)
            unset( $rates['flat_rate:23'] ); // remove: Fedex Stand Overnight ($40)
            unset( $rates['flat_rate:24'] ); // remove: Fedex Pty. Overnight ($50)
            unset( $rates['flat_rate:9'] );  // remove: USPS Express ($45)
        }

        ## 2) USPS

        if ( isset( $rates['free_shipping:19'] ) ) // For => "USPS Express (free)"
            unset( $rates['free_shipping:4'] ); // remove: USPS Priority (free)

    }

  return $rates;

}

This code should work…

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.

这篇关于具有多种运输价格选项和价格的分层运输的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆