Created
July 13, 2017 22:55
-
-
Save WPprodigy/7134a6068d7b3b8737803229e10e1ea5 to your computer and use it in GitHub Desktop.
Change shipping costs conditionally based on package contents.
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_shipping_packages', 'wc_ninja_woocommerce_package_rates', 20 ); | |
function wc_ninja_woocommerce_package_rates( $packages ) { | |
$is_warm_weather = true; | |
foreach ( $packages as $package ) { | |
$has_candy = false; | |
foreach ( $package['contents'] as $cart_product ) { | |
if ( has_term( 'clothing', 'product_cat', $cart_product['product_id'] ) ) { | |
$has_candy = true; | |
break; | |
} | |
} | |
if ( $is_warm_weather && $has_candy && sizeof( $package['rates'] ) > 0 ) { | |
foreach ( $package['rates'] as $rate ) { | |
$rate->cost = $rate->cost + 10; | |
} | |
} | |
} | |
return $packages; | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment