The code in this article is considered a customisation. As such, it's outside the scope of our support service. Should you need assistance implementing the code, please feel free to contact us to request a consultation. 


The Checkout Addons plugin introduces the possibility of adding options to an order, on the checkout page. Out of the box, the plugin doesn't pass the prices of addons to the currency conversion functions. This causes their value to remain the same for all currencies.


The best way to ensure that the prices of the checkout addons are converted correctly would be to add multi-currency support directly to the Checkout Addons plugin. Its interface could be extended to allow merchants to enter different addon prices for different currencies, and select the correct price depending on the active currency. This would require an update of the code in the original Checkout Addons plugin, and it would have to be implemented by its authors. 

If you're interested in these features, we would recommend to inform the authors of the Checkout Addons plugin, so that they can prioritise its development accordingly.


1. How to pass the prices of addons to the conversion functions

Since the Checkout Addons doesn't interface with the multi-currency core, an external patch will be needed to intercept the prices of addons and pass them to the conversion functions provided by the Aelia Currency Switcher. Below you can find the instructions to implement such an integration. 


Important notes

  • The code in this article is meant as a proof of concept. It's provided as is, without guarantees, and it's outside the scope of our support service.
  • If you're not familiar with coding, we would recommend to contact your developers. They will be able to implement, test and tweak the custom code for you.


1.1. Prepare a mini-plugin to host the code

The code to intercept and convert the prices of checkout addons can't be put inside the theme's functions.php, because that file may be loaded too late. That would make the code ineffective.


To ensure that the code runs early enough, you can implement a small plugin, as follows:

  1. Create a folder called your-plugin-name, on your local computer. You can change "your-plugin-name" to a name of your choice.
  2. Create a file called your-plugin-name.php in the new subfolder.
  3. Add a plugin header to the file: https://developer.wordpress.org/plugins/plugin-basics/header-requirements/. You can just set it to "Plugin Name: YOUR PLUGIN NAME".
  4. Add the custom code below the plugin header (see section 1.2, below).
  5. Save the file.
  6. Create a folder called wp-content/plugins/your-plugin-name on your site (e.g. via FTP).
  7. Enter the new folder on the remote server.
  8. Upload the file you just created.
  9. Go to WordPress > Plugins to enable the custom plugin.


1.2 Add the custom code to to convert the checkout addons 

When you have your custom plugin ready on your computer, you can add the following code, right under the plugin header (see step #4, in section 1.1).

/**
 * Converts the cost of the addons introduced by the Checkout Addons plugin,
 * from shop's base currency to the active currency.
 * 
 * @param float $cost
 * @return float
 */
add_filter('wc_checkout_add_ons_add_on_get_cost', function($cost) {
  return apply_filters('wc_aelia_cs_convert', $cost, get_option('woocommerce_currency'), get_woocommerce_currency());
});


After adding the custom code to your site, the prices of the checkout addons should be converted automatically, from your shop's base currency to the active currency, using the exchange rates configured in the Currency Switcher settings.


2. Contact us if you have any questions

As indicated at the top of the article, all the code examples are provided on an "as is" basis, and they fall outside the scope of our support service. Although we won't be able to implement them for you, nor provide a guarantee that they will work, we will be happy to answer any questions you might have. You can simply contact us, and we will get back to you as soon as possible.


You can purchase the Currency Switcher from our online shop.