Skip Navigation

All hooks listed in this API are available for WooCommerce Multilingual (WCML) versions >= 3.5

Multi-currency Feature

wcml_switch_currency – Run actions after the client currency for the front end is switched via AJAX requests.

availability:
WCML Version: 3.5
description:

Run your custom functions right after the client currency for the front end is switched via AJAX requests.

type:
action
category:
Multi-currency Feature
parameters:
add_action( 'wcml_switch_currency', 'the_callback_function', 10, 1 );

There is one parameter being passed to this action: new_currency.

$new_currency
(string) The new currency code is switched to, e.g. “USD”, “EUR”, etc.
hook example usage:

Example

add_action( 'wcml_switch_currency', 'my_custom_action', 10, 1 );
function my_custom_action( $new_currency ) {
	// my custom action
}
Back to the top

wcml_set_client_currency – Run actions after the client currency for the front-end is set.

availability:
WCML Version: 3.5
description:

Run your custom functions right after the client currency for the front-end is set.

type:
action
category:
Multi-currency Feature
parameters:
add_action( 'wcml_set_client_currency', 'the_callback_function', 10, 1 );

There is one parameter being passed to this action: currency.

$currency
(string) The currency code is being set in the front-end, e.g: “USD”, “EUR”, etc.
hook example usage:

Example

add_action( 'wcml_set_client_currency', 'my_custom_action', 10, 1 );
function my_custom_action( $new_currency ) {
	// my custom action
}
Back to the top

wcml_before_multi_currency_ui – Run actions before generating the Multi-currency tab in the WPML -> Woocommerce Multilingual screen.

availability:
WCML Version: 3.8.1
description:

Run actions before generating the Multi-currency tab in the WPML -> Woocommerce Multilingual screen.

type:
action
category:
Multi-currency Feature
parameters:
add_action( 'wcml_before_multi_currency_ui', 'the_callback_function' );

This action has no parameter.

hook example usage:

Example

add_action( 'wcml_before_multi_currency_ui', 'my_custom_action' );

function my_custom_action() {

	// my custom action

}
Back to the top

wcml_currency_switcher – Run actions when the currency switcher widget is being generated.

availability:
WCML Version: 3.9
description:

Run actions when the currency switcher widget is being generated.

type:
action
category:
Multi-currency Feature
parameters:
add_action( 'wcml_currency_switcher', 'the_callback_function' );

This action has no parameters.

hook example usage:

Example

add_action( 'wcml_currency_switcher', 'my_custom_action' );

function my_custom_action() {

	// my custom action

}
Back to the top

wcml_product_price_by_currency – Get the product price in selected currency.

availability:
WCML Version: 3.9
description:
  • This hook returns the custom price if entered. Otherwise, it returns the price based on the set exchange rate.
  • This hook works only on the front-end.
type:
filter
category:
Multi-currency Feature
parameters:
apply_filters( 'wcml_product_price_by_currency', integer $product_id, string $currency )
$product_id
(integer) (Required) The product ID
$currency
(string) (Required) The currency code you want to get the price for, e.g. “USD”, “EUR”, etc.
hook example usage:

Example

 // Get the EUR price of the product ID = 80 
$product_id = 80; 
$currency = 'EUR'; 
echo apply_filters( 'wcml_product_price_by_currency', $product_id, $currency );
 
Please note: Multicurrency code is not always loaded. If you find that this filter is not working, please take a look at the wcml_load_multi_currency_in_ajax hook.
Back to the top

wcml_price_currency – Get the current currency on the front end

availability:
WCML Version: 3.5
description:
  • Get the current currency set on the front-end.
  • This filter is available on the front-end.
type:
filter
category:
Multi-currency Feature
parameters:
apply_filters( 'wcml_price_currency', mixed $empty_value )
$empty_value
(mixed) (Required) Normally, this is the value the filter will be modifying. We are not filtering anything here so you should set this to NULL. This argument allows the filter’s function to receive the full list of arguments.
hook example usage:

A basic example

$current_currency = apply_filters('wcml_price_currency', NULL );
Back to the top

wcml_client_currency – Filter the currency set by the user on the front-end

availability:
WCML Version: 3.5
description:

Filter the currency set by the user on the front-end.

type:
filter
category:
Multi-currency Feature
parameters:
add_filter( 'wcml_client_currency', 'the_callback_function', 10, 1 );

There is only one parameter passed to this filter: currency.

$currency
(string) The code of the currency used on the front-end, e.g. “USD”, “EUR”, etc.
hook example usage:

Example

 /**
 * Add this code to the functions.php file of your theme.
 */
add_filter( 'wcml_client_currency', 'modify_client_currency', 10, 1 );
 
function modify_client_currency( $currency ) {
    return 'USD'; 
} 
Back to the top

wcml_load_multi_currency_in_ajax – Define whether or not the multi-currency filters for AJAX actions are loaded

availability:
WCML Version: 3.9.2
description:

This is a filter used to define whether or not the multi-currency filters for AJAX actions are loaded.

type:
filter
category:
Multi-currency Feature
parameters:
add_filter( 'wcml_load_multi_currency_in_ajax', 'the_callback_function', 10, 1 );

There is only one parameter passed to this filter: load.

$load
(bool) The boolean value to define whether or not to load AJAX actions.
hook example usage:

Example

/**
 * Add this code to the functions.php file of your theme.
 */
add_filter( 'wcml_load_multi_currency_in_ajax', 'do_not_load_multi_currency_in_ajax', 10, 1 );

function do_not_load_multi_currency_in_ajax( $load ) {

    if ( is_checkout() ) { 
        $load = false; // If this is the checkout page, do not load multi-currency filters in AJAX actions
    }

    return $load;

}
Back to the top

wcml_multi_currency_ajax_actions – Add or remove the AJAX actions that need our multi-currency filters

availability:
WCML Version: 3.1
description:

Add or remove the AJAX actions that need our multi-currency filters.

type:
filter
category:
Multi-currency Feature
parameters:
add_filter( 'wcml_multi_currency_ajax_actions', 'the_callback_function', 10, 1 );

There is only one parameter passed to this filter: ajax_actions.

$ajax_actions
(array) The array including AJAX actions.
hook example usage:

Example

/**
 * Add this code to the functions.php file of your theme.
 */
add_filter( 'wcml_multi_currency_ajax_actions', 'add_action_to_multi_currency_ajax', 10, 1 );

function add_action_to_multi_currency_ajax( $ajax_actions ) {

    $ajax_actions[] = 'ux_quickview'; // Add a AJAX action to the array
    return $ajax_actions;

}
Back to the top

wcml_is_cache_enabled_for_switching_currency – Add the currency code to the URL

availability:
WCML Version: 4.3.3
description:

This filter adds ?wcmlc={currency_code} to the URL, which specifies a query string with the currency code. This is useful when your site has cache enabled and doesn’t show currency changes correctly.

type:
filter
category:
Multi-currency Feature
parameters:
add_filter( 'wcml_is_cache_enabled_for_switching_currency', 'the_callback_function', 10, 1 );

There is only one parameter passed to this filter:

$enabled

(bool) Set to true to enable the filter.
hook example usage:

Example

/**
* Enable the query string argument on currency change.
*/
add_filter( 'wcml_is_cache_enabled_for_switching_currency', '__return_true' );

Back to the top