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 to switch between two or more UPS accounts based on order address provided by the customer in cart/checkout page when using the WooCommerce UPS Shipping Plugin with Print Label.
Note: This UPS snippet requires minimum UPS version 2.9.2. Add the following code to Appearance –> Editor –> functions.php.
To work with it, you need to have at least 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 :
Also, the array for both the country and 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 the snippet. If the customer selects “Alaska” address, then the plugin would fetch rates based on the default account mentioned in the plugin settings page.