Skip to content

Instantly share code, notes, and snippets.

@xadapter
Forked from Nishadup/function.php
Last active March 12, 2020 10:22
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 xadapter/0a0e4f1bd14d1a6b7dcbfff9d1fe122b to your computer and use it in GitHub Desktop.
Save xadapter/0a0e4f1bd14d1a6b7dcbfff9d1fe122b to your computer and use it in GitHub Desktop.
Snippet to add extra shipping cost to every UPS package. WooCommerce UPS Shipping Plugin: https://www.pluginhive.com/product/woocommerce-ups-shipping-plugin-with-print-label/
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