Skip to content

Instantly share code, notes, and snippets.

@WooForce
Last active June 7, 2016 12:22
Show Gist options
  • Save WooForce/fcfbc8b0f80baad3ab10387134080d04 to your computer and use it in GitHub Desktop.
Save WooForce/fcfbc8b0f80baad3ab10387134080d04 to your computer and use it in GitHub Desktop.
Price adjustment if the cart total exceed given value.
add_filter( 'woocommerce_package_rates', 'wf_rate_adjustment_if_cart_total_exceed', 10, 2 );
function wf_rate_adjustment_if_cart_total_exceed( $available_shipping_methods, $package ) {
$minimum_cart_price_to_adjust = 30; //give value here
$shipping_services_with_price = array(
'wf_shipping_ups:01' => 0, //give shipping service with adjustment price in percent.
'wf_shipping_ups:02' => 0
);
$cart_total = WC()->cart->cart_contents_total;
if( $cart_total > $minimum_cart_price_to_adjust ){
foreach ($available_shipping_methods as $key => $value) {
if( array_key_exists( $key, $shipping_services_with_price ) ){
$available_shipping_methods[$key]->cost *= $shipping_services_with_price[$key] ;
}
}
}
return $available_shipping_methods;
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment