Skip to content

Instantly share code, notes, and snippets.

@xadapter
Forked from Nishadup/function.php
Last active March 12, 2020 10:06
Show Gist options
  • Save xadapter/2fa2f7704db1124c0d4916d53a79fb9b to your computer and use it in GitHub Desktop.
Save xadapter/2fa2f7704db1124c0d4916d53a79fb9b to your computer and use it in GitHub Desktop.
Snippet to round off the weight and dimensions nearest to the upper integer if destination country is Switzerland. WooCommerce FedEx Shipping Plugin: https://www.pluginhive.com/product/woocommerce-fedex-shipping-plugin-with-print-label/
add_filter('wf_fedex_request', 'remove_fraction_for_switz', 10, 2);
function remove_fraction_for_switz($request, $order) {
if ($request['RequestedShipment']['Shipper']['Address']['CountryCode'] == 'CH') {
$request['RequestedShipment']['TotalWeight']['Value'] = ceil($request['RequestedShipment']['TotalWeight']['Value']);
foreach ($request['RequestedShipment']['RequestedPackageLineItems'] as $key => &$value) {
if( isset( $value['Dimensions'] ) ){
$value['Dimensions']['Length'] = ceil( $value['Dimensions']['Length'] );
$value['Dimensions']['Width'] = ceil( $value['Dimensions']['Width'] );
$value['Dimensions']['Height'] = ceil( $value['Dimensions']['Height'] );
$value['Weight']['Value'] = ceil( $value['Weight']['Value'] );
}
}
}
return $request;
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment