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:
This code should work…