WooCommerce Multi-currency
The WooCommerce Multi‑Currency plugin automatically converts prices based on the customer’s country, billing address, or a manual currency switcher. When an agent creates a manual order in the admin area, the system often defaults to the store’s base currency. The code below forces the correct currency to apply during phone order creation so that the customer sees accurate prices in their own currency.
Limitations
This integration works only when the agent uses the Go to Cart/Checkout button (frontend checkout mode) or when the plugin is set to Run at frontend. It does not work for orders that are completed entirely from the admin without a frontend redirect.
The Complete Code Snippet
|
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 |
add_action("wpo_before_switch_customer_apply_cart_data", function ($cart) { if ( ! class_exists('WOOMCMultiCurrencyApp') ) { return; } $current_user = WOOMCMultiCurrencyApp::instance()->getUser(); $country = ''; if ( isset($cart['customer']['billing_country']) && $cart['customer']['billing_country'] ) { $country = $cart['customer']['billing_country']; } if ( ! $country ) { $country = get_user_meta(get_current_user_id(), 'billing_country', true); } if ( ! $country ) { return; } $current_user->set_country($country); $country_obj = new WOOMCMultiCurrencyCountry($country); $current_user->set_currency($country_obj->getCurrency()); }); |
What the code does
| Element | Explanation |
|---|---|
wpo_before_switch_customer_apply_cart_data | An action hook that fires just before the plugin applies the selected customer’s data to the cart. |
WOOMCMultiCurrencyApp::instance()->getUser() | Retrieves the current user object from the multi‑currency plugin. |
| Billing country detection | The code first looks for the billing country in the cart data ($cart['customer']['billing_country']). If that is empty, it falls back to the user’s stored billing country meta field. |
set_country( $country ) | Tells the multi‑currency plugin which country to use for price conversion. |
WOOMCMultiCurrencyCountry( $country ) | Creates a country object that holds the conversion rate and currency symbol for that country. |
set_currency(...) | Applies the correct currency (e.g., EUR, GBP, JPY) to the current session before the cart totals are calculated. |
Why you need this code
Without this hook, a phone order created for a customer in France might be calculated in USD instead of EUR, leading to incorrect totals and customer dissatisfaction.
How to implement it
- Copy the code snippet.
- Add it as a new snippet using the Code Snippets plugin (same steps as the ThemeHigh guide).
- Title it “Phone Orders – Multi‑Currency Fix”.
- Activate the snippet.
Important note
The multi‑currency plugin must be active and properly configured with exchange rates for the countries you serve. The customer must have a billing country assigned (either in the phone order cart or on their user profile).