Skip to content

Instantly share code, notes, and snippets.

@WooForce
Created June 22, 2016 17:21
Show Gist options
  • Save WooForce/552a9605476ad22f5df4239b385eb381 to your computer and use it in GitHub Desktop.
Save WooForce/552a9605476ad22f5df4239b385eb381 to your computer and use it in GitHub Desktop.
Shipping Pro - discard the base cost of one of the shipping classes if both of them come up in the cart based on states
add_filter( 'wf_woocommerce_shipping_pro_shipping_costs', 'wf_hide_base_cost_for_non_westcost');
function wf_hide_base_cost_for_non_westcost( $costs ) {
$shipping_state = WC()->customer->shipping_state;
$states_requires_price_adjustment = array('CA');
$shippingclass_requires_price_adjustment = array('shipping-class-a');
if(!empty($shipping_state) && in_array($shipping_state,$states_requires_price_adjustment)){
foreach ($costs as $method_group => $method_cost) {
if(isset($method_cost['shipping_name']) && isset($method_cost['cost'])){
if(count($method_cost['cost']) > 1){
foreach($method_cost['cost'] as $shipping_group => $shipping_cost){
if(in_array($shipping_group,$shippingclass_requires_price_adjustment)){
$costs[$method_group]['cost'][$shipping_group] -= 13;
}
}
}
}
}
}
return $costs;
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment