• Resolved dovroc

    (@dovroc)


    I need to change the currency depending on a specific user role. I want to change the currency to EUR for customers who are defined as user role EU paying and those who are customers to still be able to pay in GBP.

    I have this code and I’ve used $WOOCS->set_currency(‘EUR’) but it doesn’t seem to change the currency. Any help will be appreciated.

    add_filter(‘woocommerce_currency’, ‘set_role_currency’, 100);
    function set_role_currency($currency){
    global $current_user;

    if (in_array(‘eu_paying’, $current_user->roles)) {
    global $WOOCS;
    $WOOCS->set_currency(‘EUR’);
    return ‘EUR’;
    }
    return $currency; //return your woocommerce default currency
    }`

Viewing 3 replies - 1 through 3 (of 3 total)
  • Plugin Support mediawebster

    (@mediawebster)

    Hello

    Please try to yse:

    add_action('wp_head', 'set_role_currency', 100);
    function set_role_currency(){
    global $current_user;
    
    if (in_array('eu_paying', $current_user->roles) && class_exists('WOOCS')) {
    global $WOOCS;
    $WOOCS->set_currency('EUR');
    }
    
    }
    Thread Starter dovroc

    (@dovroc)

    Thank you! This still does not work. Using “add_action()” does not even get into the function.
    I’ve reverted back to “add_filter()” and it goes into the function and passes the class_exists(‘WOOCS’) but it seems that $WOOCS->set_currency(‘EUR’) doesn’t do anything as the price and currency stay the same.

    Please advise.

    Plugin Support mediawebster

    (@mediawebster)

    Hello

    Using “add_action()” does not even get into the function. – Read
    this – https://developer.wordpress.org/reference/functions/add_action/

    it seems that $WOOCS->set_currency(‘EUR’) doesn’t do anything – All currencies are switched using this function. The reason may be that your condition is not met OR do you have another customization that switches the currency

Viewing 3 replies - 1 through 3 (of 3 total)

The topic ‘Switch currency depending on a specific user role’ is closed to new replies.