Last active
November 26, 2017 21:03
-
-
Save bolderelements/d4f295ebdd0e277d984e13b9699fca8b to your computer and use it in GitHub Desktop.
Add Different Base Fee to Shipping Option
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
add_filter( 'woocommerce_package_rates', 'add_shipping_option_base_fee', 10, 2 ); | |
function add_shipping_option_base_fee( $rates, $package ) { | |
foreach( $rates as $key => $rate ) { | |
// reset defaults | |
$highest_priority = $highest_class = 0; | |
// Do not apply base fee if not the right option | |
if( $rate->id !== 'betrs_shipping:1-1' ) continue; | |
// find highest priority class (BE Table Rate Shipping Only) | |
foreach( $package['contents'] as $key => $values ) { | |
$shipping_class = $values[ 'data' ]->get_shipping_class(); | |
$get_priority = get_term_meta( $shipping_class->get_id(), 'priority', true ); | |
if( $get_priority > $highest_priority ) { | |
$highest_priority = $get_priority; | |
$highest_class = $shipping_class->get_id(); | |
} | |
} | |
switch( $highest_class ) { | |
case 'ornaments': | |
$rates[ $key ]->cost += 4.00; | |
break; | |
case 'cake-toppers': | |
$rates[ $key ]->cost += 5.00; | |
break; | |
case 'cutting-boards': | |
default: | |
$rates[ $key ]->cost += 0.00; | |
break; | |
} | |
} | |
return $rates; | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment