WOOCS - WooCommerce Currency Switcher


This function works with WOOCS storage where keeps different values, current currency for example.

global $WOOCS;

Possible keys:

  • woocs_current_currency – here keeps selected on the front current currency code
  • woocs_user_country – if enabled GEO IP option its keeps country code of the site visitor


You can use this function to keep any your own intermediate values by your own logic to use them for example in the code of any another plugin or wp theme functionality! Get any value from the plugin storage by $WOOCS->storage->get_val() function.

Also read: https://currency-switcher.com/function/woocs-set_currency/

Use this function for any manipulations with your site logic. Examples:

A piece of the code from the plugin as a simple example:

$rules = $this->get_geo_rules();
$pd = WC_Geolocation::geolocate_ip();
$this->storage->set_val('woocs_user_country', $pd['country']);

Example how to manipulate with the data in the code flow:

$tmp_curr_currency = $this->current_currency;
$this->current_currency = $user_currency;
$this->storage->set_val('woocs_current_currency', $user_currency);

if ($user_currency == $this->default_currency)
    $cart_price = $this->back_convert($cart_item['line_total'], $currencies[$tmp_curr_currency]['rate']) / $cart_item['quantity'];
} else
    $cart_price = $cart_item['line_total'] / $cart_item['quantity'];

$wc_price = $this->wc_price($cart_price, true);

$this->current_currency = $tmp_curr_currency;
$this->storage->set_val('woocs_current_currency', $tmp_curr_currency);