Last active
October 24, 2017 14:39
-
-
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/
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_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