Public Ticket #3563530

multi currency

Closed
Comments
15 Tickets 3
Burak ARICI Arıcı started the conversation 3 years ago on January 17, 2024 at 2:06pm

I want to show euro to b2b customers and CFA to b2c customers. How can I do that? I use Fox curreny switcher plugin. I wrote to them. But they said they didn't know which hooks you used. I created dynamic rules. But it didn't work either. Can you help me?

2,762
KingsPlugins replied 3 years ago on January 17, 2024 at 5:41pm

Hi there,

Please let me know:


- Should B2B and B2C users be able to also switch the currency? Or should it always be forced to EUR or CFA?

In other words, are you looking to set the default to EUR but allow them to change it, or do you need to always force them to only make EUR purchases?


Looking forward to your reply,


Kind regards,

Stefan

15 Tickets 3
Burak ARICI Arıcı replied 3 years ago on January 18, 2024 at 7:23am

b2b and b2c users should be able to change currency. However, by default b2b users should see euro, b2c users and those who are not logged in should see cfa. Thank you.

2,762
KingsPlugins replied 3 years ago on January 18, 2024 at 6:22pm

Thank you for clarifying that,

I looked into it and I wrote a snippet that I believe can do this:


add_action('init', function(){
    if (class_exists('WOOCS')){
        $user_id = get_current_user_id();
        $is_b2b = get_user_meta($user_id,'b2bking_b2buser', true);
        $already_set = get_user_meta($user_id, 'currency_set', true);
        if ($already_set !== 'yes'){
            global $WOOCS;
            if ($is_b2b === 'yes'){
                $WOOCS->set_currency('EUR');
            } else {
                $WOOCS->set_currency('CFA');
            }
            update_user_meta($user_id, 'currency_set', 'yes');
        }
    }
});

Here is where it is a bit tricky: the snippet can force a default currency, but the problem is I do not know how we can check whether the user manually clicked on EUR / CFA. If the user chose a currency manually, we should not force the currency anymore.

Since I do not know how / if that can be done, what I did is that I made it set the default currency for the user only 1 time (only the first time).

It's possible the FOX currency team may be able to help you improve it if you share the code with them,


Kind regards,

Stefan

1

Sign In