Switch between two or more UPS accounts based on order address provided by the customer in cart/checkout page

This code snippet will help you tomer in cart/checkout page.

Note : This UPS snippet requires minimum UPS version 2.9.2. Add the following code tor –> functions.php.

To work with it, you need to have atleast 2 UPS accounts. One should be configured at the plugin settings level.The details of the other account should be updated in the snippet for the following fields :

‘shipper_number’
‘user_id’
‘password’
‘access_key’
‘origin_addressline’
‘origin_postcode’
‘origin_city’
‘origin_state’
‘origin_country’

Also the array for country and the state should also be updated. i.e. For the country and states for which you want shipping to be done via this UPS account.
For example, if you want the UPS account to provide rates for Canada, Ontario, then you can remove the existing array of ‘US’ and place another array as shown below:

‘CA’ => array(
‘ON’ => ‘Ontario’,
‘AL’ => ‘Alberta’,

Similarly, for shipment requests you would need to add the same details.

Once you add these, if the customer in the cart page selects a California address, then the rates would come based on the account mentioned in snippet.
If the customer selects “Alaska” address, then the plugin would fetch rates based on the default account mentioned in plugin settings page.

Leave a Reply