Skip to content

Instantly share code, notes, and snippets.

@xadapter
Last active September 19, 2019 06:19
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save xadapter/8891ba54b0cd2a642813e83e1d7e9810 to your computer and use it in GitHub Desktop.
Save xadapter/8891ba54b0cd2a642813e83e1d7e9810 to your computer and use it in GitHub Desktop.
Snippet to change UPS account details in rate request when Access Point address has been selected. WooCommerce UPS Shipping Plugin with Print Label by PluginHive - https://www.pluginhive.com/product/woocommerce-ups-shipping-plugin-with-print-label/
/**
* Snippet to change UPS account details in rate request when Access Point address has been selected.
* Created at : 27 Aug 2018
* Updated at : 27 Aug 2018
* PluginHive Plugins : https://www.pluginhive.com/plugins/
* Gist Link : https://gist.github.com/xadapter/8891ba54b0cd2a642813e83e1d7e9810
*/
if( ! function_exists('ph_change_ups_account_for_accesspoint_rate_request') ) {
function ph_change_ups_account_for_accesspoint_rate_request( $xml_request, $package ){
// UPS account details that has been configured in plugin settings page
$general_ups_account_details = array(
'user_id' => 'ups_user_id',
'password' => 'ups_password',
'access_key' => 'ups_access_key',
'acc_no' => 'ups_acc_no'
);
// UPS account details to be used in rate request if Access point has been selected
$access_point_ups_account_details = array(
'user_id' => 'access_point_user_id',
'password' => 'access_point_password',
'access_key' => 'access_point_access_key',
'acc_no' => 'access_point_acc_no'
);
$xml_request_arr = explode( '<RatingServiceSelectionRequest>', $xml_request );
$xml_request_arr[1] = '<RatingServiceSelectionRequest>'.$xml_request_arr[1];
$xml_request_arr_obj_1 = new SimpleXMLElement($xml_request_arr[1]);
$shipment_indication_code = ! empty($xml_request_arr_obj_1->Shipment->ShipmentIndicationType) ? trim((string) $xml_request_arr_obj_1->Shipment->ShipmentIndicationType->Code) : null;
// Replace the account details when Accesspoint has been selected
if( $shipment_indication_code == '02' || $shipment_indication_code == '01' ) {
$xml_request = str_replace( $general_ups_account_details, $access_point_ups_account_details, $xml_request );
}
return $xml_request;
}
add_filter( 'wf_ups_rate_request', 'ph_change_ups_account_for_accesspoint_rate_request', 10, 2 );
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment