-
-
Save xadapter/49317db7e764fac6163408cb92ae4a0d to your computer and use it in GitHub Desktop.
Snippet to add an extra coast to each and every UPS package in a shipment. WooCommerce UPS Shipping Plugin: https://www.pluginhive.com/product/woocommerce-ups-shipping-plugin-with-print-label/
This file contains 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', 'wf_modify_ups_rate', 10, 2); | |
function wf_modify_ups_rate($xml, $packages){ | |
$amount_to_add = 3; //change this with your value to be added with each packages | |
if($xml){ | |
for( $i=0; $i<count($packages); $i++ ){ | |
//if negotiated rate | |
if( isset($xml->RatedShipment->NegotiatedRates->NetSummaryCharges->GrandTotal->MonetaryValue) ){ | |
if( property_exists($xml->RatedShipment->NegotiatedRates->NetSummaryCharges, 'TotalChargesWithTaxes') ){ | |
$xml->RatedShipment->NegotiatedRates->NetSummaryCharges->TotalChargesWithTaxes->MonetaryValue += $amount_to_add; | |
}else{ | |
$xml->RatedShipment->NegotiatedRates->NetSummaryCharges->GrandTotal->MonetaryValue += $amount_to_add; | |
} | |
} | |
// if normal rate | |
$xml->RatedShipment->TotalCharges->MonetaryValue += $amount_to_add; | |
} | |
} | |
return $xml; | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment