Skip to content

Instantly share code, notes, and snippets.

@Nishadup
Created April 3, 2018 14:56
Show Gist options
  • Save Nishadup/cca7062979718eaeba2c315e4ea20c64 to your computer and use it in GitHub Desktop.
Save Nishadup/cca7062979718eaeba2c315e4ea20c64 to your computer and use it in GitHub Desktop.
Code snippet to limit insured amount to 100 in the cart with Xadapter FedEx plugin https://www.xadapter.com/product/woocommerce-fedex-shipping-plugin-with-print-label/
add_filter('wf_fedex_calculate_shipping_request', 'modify_fedex_request', 10, 2);
function modify_fedex_request($fedex_requests, $fedex_packages){
$insurance_amount = 100; // New Insurance amount
foreach ($fedex_requests as $req_no => &$request) {
if( isset($request['RequestedShipment']['TotalInsuredValue']['Amount']) ) {
$count = 0;
foreach( $request['RequestedShipment']['RequestedPackageLineItems'] as $key => $item ) {
$request['RequestedShipment']['RequestedPackageLineItems'][$key]['InsuredValue']['Amount'] = $insurance_amount;
$count++;
}
$request['RequestedShipment']['TotalInsuredValue']['Amount'] = $insurance_amount * $count;
}
}
return $fedex_requests;
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment