Last active
June 20, 2018 03:04
-
-
Save bolderelements/395a7d5fefa0ba64a85773c5c3834967 to your computer and use it in GitHub Desktop.
Add shipping for surcharge for large items
This file contains 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_length = 0; | |
// Do not apply base fee if not the right option | |
if( $rate->id !== 'betrs_shipping:1-1' ) continue; | |
// find product with greatest length | |
foreach( $package['contents'] as $key => $values ) { | |
$item_length = $values[ 'data' ]->get_length(); | |
if( $item_length > $highest_length ) { | |
$highest_length = $item_length; | |
} | |
} | |
// Add $5 surcharge on orders with items larger than 21cm | |
if( $highest_length > 21 ) { | |
$rates[ $key ]->cost += 5.00; | |
} | |
} | |
return $rates; | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment