Created
June 28, 2016 19:12
-
-
Save WooForce/6ad385389c11ce33f3c549fc022a515d to your computer and use it in GitHub Desktop.
Price adjustment for a certain state and service.
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('wf_ups_rate', 'wf_rate_adjustment', 10, 1); | |
function wf_rate_adjustment($rate_xml_object){ | |
$states_requires_price_adjustment = array('CA'); //add state code here | |
$service_code_requires_price_adjustment = array('01'=>0.1, '02'=>0.5, '03'=>0.12); //add service code with adjustment value. | |
$shipping_state = WC()->customer->shipping_state; | |
if(!empty($shipping_state) && in_array($shipping_state, $states_requires_price_adjustment) ){ | |
$code = (string)$rate_xml_object->RatedShipment->Service->Code; | |
if( array_key_exists($code, $service_code_requires_price_adjustment) ){ | |
if ( isset( $rate_xml_object->RatedShipment->NegotiatedRates->NetSummaryCharges->GrandTotal->MonetaryValue ) ){ | |
$rate_cost = (float) $rate_xml_object->RatedShipment->NegotiatedRates->NetSummaryCharges->GrandTotal->MonetaryValue; | |
$rate_cost = $rate_cost * $service_code_requires_price_adjustment[ $code ]; | |
$rate_xml_object->RatedShipment->NegotiatedRates->NetSummaryCharges->GrandTotal->MonetaryValue = $rate_cost; | |
} | |
else{ | |
$rate_cost = (float) $rate_xml_object->RatedShipment->TotalCharges->MonetaryValue; | |
$rate_cost = $rate_cost * $service_code_requires_price_adjustment[ $code ]; | |
$rate_xml_object->RatedShipment->TotalCharges->MonetaryValue = $rate_cost; | |
} | |
} | |
} | |
return $rate_xml_object; | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment