Created
July 19, 2019 15:42
-
-
Save debabratakarfa/674829605c8b73be26102bebb1594832 to your computer and use it in GitHub Desktop.
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('wf_ups_rate', 'wf_modify_ups_rate', 10, 2); | |
function wf_modify_ups_rate($xml, $packages){ | |
//Config this array with box dimensions and rate to be added. | |
$extra_coast = array( | |
'7,9,8' => 10, | |
'10,6,8' => 15, | |
); | |
if($xml){ | |
foreach ($extra_coast as $extra_coast_dim => $amount_to_add) { | |
$dimension_arrey = explode(",",$extra_coast_dim); | |
foreach ($packages as $i => $package) { | |
if( compare_package_dimensions($package['Package']['Dimensions'], $dimension_arrey) ){ | |
//if negotiated rate | |
if( isset($xml->RatedShipment->NegotiatedRates->NetSummaryCharges->GrandTotal->MonetaryValue) ){ | |
if( property_exists($xml->RatedShipment->NegotiatedRates->NetSummaryCharges, 'TotalChargesWithTaxes') ){ | |
$xml->RatedShipment->NegotiatedRates->NetSummaryCharges->TotalChargesWithTaxes->MonetaryValue += $amount_to_add; | |
}else{ | |
$xml->RatedShipment->NegotiatedRates->NetSummaryCharges->GrandTotal->MonetaryValue += $amount_to_add; | |
} | |
} | |
// if normal rate | |
$xml->RatedShipment->TotalCharges->MonetaryValue += $amount_to_add; | |
} | |
} | |
} | |
} | |
return $xml; | |
} | |
function compare_package_dimensions($package, $dimension_arrey){ | |
foreach ($dimension_arrey as $key => &$value) { | |
if( isset($package['Length']) && $value == $package['Length'] ){ | |
unset($package['Length']); | |
}elseif( isset($package['Width']) && $value == $package['Width'] ){ | |
unset($package['Width']); | |
}elseif( isset($package['Height']) && $value == $package['Height'] ){ | |
unset($package['Height']); | |
} | |
} | |
if( empty($package['Length']) && empty($package['Width']) && empty($package['Height']) ){ | |
return true; | |
} | |
return false; | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment