Skip to content

Instantly share code, notes, and snippets.

@renjith-ph
Last active December 28, 2018 05:23
Show Gist options
  • Select an option

  • Save renjith-ph/87836fcb9bb90c7ddc96bafa94e1da60 to your computer and use it in GitHub Desktop.

Select an option

Save renjith-ph/87836fcb9bb90c7ddc96bafa94e1da60 to your computer and use it in GitHub Desktop.
Snippet to to adjust importer price for international Shipment FedEx
/**
* Snippet to to adjust importer price for international Shipment FedEx
* Created at : 24 Dec 2018
* PluginHive Plugins : https://www.pluginhive.com/plugins/
*/
add_filter( 'ph_fedex_commodities', 'ph_importer_price_adjust', 11, 3);
public function ph_importer_price_adjust($commodoties,$request,$fedex_packages){
$importer_price = array(
/* Experiment */
'US' => array('7344'=>'-26.5','2362'=>'-26.5'),
// 'US' => array('2239'=>'-26.5'),
// 'US' => array('5576'=>'-26.5'),
// 'US' => array('2219'=>'-26.5'),
// 'US' => array('2126'=>'-26.5'),
// 'US' => array('2115'=>'-26.5'),
// 'US' => array('2096'=>'-26.5'),
// 'US' => array('2025'=>'-26.5'),
// 'US' => array('1965'=>'-26.5'),
// 'US' => array('1927'=>'-26.5'),
// 'US' => array('1876'=>'-26.5'),
// 'US' => array('1529'=>'-26.5'),
'UK' => array('1493'=>'-26.5'),
);
//for importer price adjustment fill $importer_price like below format
//'country_code'=>array('product_id'=>'importer price percentage with '+' or '-')
$destination_coutry = $request['RequestedShipment']['Recipient']['Address']['CountryCode'];
print_r($commodoties);
if($request['RequestedShipment']['Shipper']['Address']['CountryCode'] != $request['RequestedShipment']['Recipient']['Address']['CountryCode']){
if(!empty($importer_price)){
foreach($importer_price as $country => $rule){
if($country == $destination_coutry){
foreach($rule as $product => $price){
foreach($commodoties as $key=>$value){
if($key == $product || '*' == $product){
$commodoties[$key]['UnitPrice']['Amount'] = $value['UnitPrice']['Amount'] + (($price)/100)*$value['UnitPrice']['Amount'];
}
}
}
}
}
}
}
$request['RequestedShipment']['CustomsClearanceDetail']['Commodities'] = $commodities;
return $commodoties;
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment