Created
August 26, 2016 12:31
-
-
Save WooForce/6a1a1f9b9d4714cf22ad392bc881e617 to your computer and use it in GitHub Desktop.
FedEx - Change the customs value and commodity description
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_fedex_request','wf_fedex_label_request_callback', 10, 2 ); | |
function wf_fedex_label_request_callback($request,$order){ | |
$custom_products = array( | |
'Product-1' => array( //Replace Product-1 with your product name | |
'Description' => 'sample descrition for product-1', //Enter prodct description here or keep it blank | |
'Amount' => 150.5 //Enter new amount of produt here or keep it blank | |
), | |
'product2' => array( | |
'Description' => 'sample descrition for product-2', | |
'Amount' => 20 | |
) | |
); | |
$commodities = !empty( $request['RequestedShipment']['CustomsClearanceDetail']['Commodities'] ) ? $request['RequestedShipment']['CustomsClearanceDetail']['Commodities']: array() ; | |
$total_amount = 0; | |
foreach ( $commodities as $product_id => $value ) { | |
if ( array_key_exists( $value['Name'], $custom_products ) ){ | |
if( !empty($custom_products[$value['Name']]['Description'] ) ){ | |
$request['RequestedShipment']['CustomsClearanceDetail']['Commodities'][$product_id]['Description'] = $custom_products[$value['Name']]['Description'] ; | |
} | |
if( !empty($custom_products[$value['Name']]['Amount']) ){ | |
$request['RequestedShipment']['CustomsClearanceDetail']['Commodities'][$product_id]['UnitPrice']['Amount'] = $custom_products[$value['Name']]['Amount']; | |
} | |
} | |
$total_amount += (float)$request['RequestedShipment']['CustomsClearanceDetail']['Commodities'][$product_id]['UnitPrice']['Amount']; | |
} | |
if( isset( $request['RequestedShipment']['CustomsClearanceDetail']['CustomsValue']['Amount'] ) ){ | |
$request['RequestedShipment']['CustomsClearanceDetail']['CustomsValue']['Amount'] = $total_amount; | |
} | |
return $request; | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment