PluginUs.Net - Business Tools for WooCommerce and WordPress

[realize your idea - make your dreams come true]

Support Forum

You need to log-in to create request (topic) to the support

Add compatibility to our discount plugin

The support doesn work on Saturdays and Sundays, so some Friday requests can be answered on Monday. If you have problems with registration ask help on contact us page please
If you not got email within 24~36 business hours, firstly check your spam box, and if no any email from the support there - back to the forum and read answer here. DO NOT ANSWER ON EMAILS [noreply@pluginus.net] FROM THE FORUM!! Emails are just for your info, all answers should be published only here.
The support doesn work on Saturdays and Sundays, so some Friday requests can be answered on Monday.

Hi guys,

I'm the author of the"Taxonomy/Term and Role based Discounts for WooCommerce" plugin that you can find here: https://wordpress.org/plugins/taxonomy-discounts-woocommerce/

We're having an issue while both our plugin and your currency switcher plugin are active. We store the original product price on the cart item, on a custom array index of each cart line, and then each time the cart is loaded from the session, we just calculate the discount again to show it on the cart. The problem is that when the currency switches, our base/original price is the same value as the previous currency so each time the user changes the currency and there are items on the cart, the values are changing constantly because calculations are made based on the previous currency and then stored again on our array but as the new currency.

Long story short: it's a mess! We're not expecting the currency to change while there are products on the cart.

Do you have any helper function we can use to convert the values, each time the currency is changed by the user, and make our plugin compatible?

Hello

All prices should be stored in the base currency

Before adding to the array, you should do the reverse conversion

if (class_exists('WOOCS')) {

global $WOOCS;

$currency = $WOOCS->current_currency;

$currencies = $WOOCS->get_currencies();

$rate = $currencies[$currency]['rate'];

$Your_price = floatval$Your_price) / $rate;

}

Do you run any action when the currency is changed, one that we can hook into and do our stuff?

Looking at the way we're doing things in our plugin, it's more transparent to convert the array on the car each time the currency is changed.

Hello

Please  read  this -  https://currency-switcher.com/codex#actions and https://currency-switcher.com/codex#filters

Conversion Hooks - woocs_raw_woocommerce_price  and woocs_woocommerce_variation_prices

Hi again,

I couldn't find any hook that runs when the currency is changed.

I think this change to the WOOCS->set_currency() method could work for me, or any other developer that wants to do anything when the currency is changed:

Basically, before changing the currency we store the current/previous currency:

$previous_currency = $this->current_currency;

And then at the end run the action:

do_action( 'woocs_currency_changed', $previous_currency, $currency );

Could you implement this, please?

It doesn't make any sense. 'woocs_currency_changed'  - this will just work on every page load

In fact, the currency switches when the page is reloaded.

so just check the current currency for example in the hook"wp_head"

OK, I wasn't aware this function runs on every page load.

So there's nowhere in your code, that an action can be created, passing the previous currency and new currency only when it changes?

Hello

Unfortunately there is no such hook.