Skip to content

Instantly share code, notes, and snippets.

@Nishadup
Last active October 24, 2017 14:39
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 1 You must be signed in to fork a gist
  • Save Nishadup/e5ec650431dfaec7af578af94a976828 to your computer and use it in GitHub Desktop.
Save Nishadup/e5ec650431dfaec7af578af94a976828 to your computer and use it in GitHub Desktop.
Snippet to add extra weight with each package of the rate request with Woocommerce UPS plugin. https://www.xadapter.com/product/woocommerce-ups-shipping-plugin-with-print-label/
add_filter( 'wf_ups_rate_request', 'adjust_package_weight', 20, 2);
function adjust_package_weight( $rate_request_data, $package ){
$package_extra_weight = 5;
$req_arr = explode('<?xml version="1.0" ?>', $rate_request_data);
$xml_obj = new SimpleXMLElement( $req_arr[2] );
foreach ($xml_obj->Shipment->Package as $key => $package) {
$package->PackageWeight->Weight += $package_extra_weight;
}
$doc = new DOMDocument();
$doc->formatOutput = TRUE;
$doc->loadXML($xml_obj->asXML());
$req_arr[2] = str_replace( '<?xml version="1.0"?>', '', $doc->saveXML() ) ;
return implode('<?xml version="1.0" ?>', $req_arr);
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment