Available YayCurrency Hooks
You can add these hooks to variables in template.php to alter the data that generates the switcher.
Custom Variable args in template.php
add_filter('yay_currency_switcher_template_args', 'yay_currency_switcher_template_args');
function yay_currency_switcher_template_args( $args ) {
$args['is_show_flag'] = '0'; // if you don't want to show flag in Dropdown and otherwise '1'...Default: get value in settings.
$args['is_show_currency_name'] = '0'; // if you don't want to show Currency name in Dropdown and otherwise '1'...Default: get value in settings.
$args['is_show_currency_code'] = '0'; // if you don't want to show Currency code in Dropdown and otherwise '1'...Default: get value in settings.
$args['switcher_size'] = 'large'; // custom switcher size ( small | large )
//...
return $args;
}
Custom currency code in Dropdown
add_filter('yay_currency_switcher_change_currency_code', 'yay_currency_custom_currency_code_dropdown_switcher');
function yay_currency_custom_currency_code_dropdown_switcher( $currency_code ) {
return 'EUR' === $currency_code ? 'Eu' : $currency_code;
}
Add custom wrapper switcher class in Dropdown
add_filter('yay_currency_switcher_class', 'yay_currency_custom_switcher_class_wrapper');
function yay_currency_custom_switcher_class_wrapper( $wrapper_class ) {
$wrapper_class.= ' your-custom-class';
return $wrapper_class;
}
Custom selected currency in Dropdown
add_filter('yay_currency_get_id_selected_currency', 'yay_currency_get_id_selected_currency');
function yay_currency_get_id_selected_currency( $currency_ID ) {
$currency_ID = 238;
return $currency_ID;
}
Added : yay_currency_custom_currency_code_by_force_country hook, allow custom currency with force payment country
add_filter( 'yay_currency_custom_currency_code_by_force_country', 'yay_currency_custom_currency_code_by_force_country', 10, 1);
function yay_currency_custom_currency_code_by_force_country( $currency_code ) {
if( 'CAD' !== $currency_code ) {
$currency_code = 'USD';
}
return $currency_code;
}
Added: filter hook hide dropdown/switcher in analytics
add_filter('yay_currency_hide_dropdown_filter_analytics', '__return_true');
Added: filter hook yay_currency_convert_all_orders_to_base detect convert orders
add_filter('yay_currency_convert_all_orders_to_base', 'yay_currency_convert_all_orders_to_base', 10, 1 );
function yay_currency_convert_all_orders_to_base($value) {
return 'no';
}
Get cart subtotal by current currency: yay_currency_get_cart_subtotal
usage:
use Yay_Currency\Helpers\YayCurrencyHelper;
$current_currency = YayCurrencyHelper::detect_current_currency();
$cart_subtotal = apply_filters( 'yay_currency_get_cart_subtotal', 0, $current_currency );
Get the shipping total by the current currency or fallback currency: yay_currency_get_shipping_total (PRO version only).
usage:
use Yay_Currency\Helpers\YayCurrencyHelper;
//9.1. Get the shipping total by current currency
$current_currency = YayCurrencyHelper::detect_current_currency();
$cart_total = apply_filters( 'yay_currency_get_shipping_total', 0, $current_currency, false );
//9.2. Get the shipping total by fallback currency
$fallback_currency = YayCurrencyHelper::get_fallback_currency();
$cart_total = apply_filters( 'yay_currency_get_shipping_total', 0, $fallback_currency, true );
Get the total discount by the current currency or fallback currency: yay_currency_get_discount_total (PRO version only).
usage:
use Yay_Currency\Helpers\YayCurrencyHelper;
//10.1. Get the total discount by current currency
$current_currency = YayCurrencyHelper::detect_current_currency();
$cart_total = apply_filters( 'yay_currency_get_discount_total', 0, $current_currency, false );
//10.2. Get the total discount by fallback currency
$fallback_currency = YayCurrencyHelper::get_fallback_currency();
$cart_total = apply_filters( 'yay_currency_get_discount_total', 0, $fallback_currency, true );
Get the total tax by the current currency: yay_currency_get_total_tax (PRO version only).
usage:
use Yay_Currency\Helpers\YayCurrencyHelper;
$current_currency = YayCurrencyHelper::detect_current_currency();
$cart_total = apply_filters( 'yay_currency_get_total_tax', 0, $current_currency );
Get the total fee by current currency: yay_currency_get_fee_total (PRO version only).
usage:
use Yay_Currency\Helpers\YayCurrencyHelper;
$current_currency = YayCurrencyHelper::detect_current_currency();
$cart_total = apply_filters( 'yay_currency_get_fee_total', 0, $current_currency );
Get the cart total by the current currency or fallback currency: yay_currency_get_cart_total (PRO version only).
usage:
use Yay_Currency\Helpers\YayCurrencyHelper;
//13.1. Get the cart total by by current currency
$current_currency = YayCurrencyHelper::detect_current_currency();
$cart_total = apply_filters( 'yay_currency_get_cart_total', 0, $current_currency, false );
//13.2. Get the cart total by by fallback currency
$fallback_currency = YayCurrencyHelper::get_fallback_currency();
$cart_total = apply_filters( 'yay_currency_get_cart_total', 0, $fallback_currency, true );
Get the exchange rate for the current currency: yay_currency_rate
usage:
$rate_fee = apply_filters('yay_currency_rate',1);
Customize the current currency based on your conditions: yay_currency_apply_currency
usage:
use Yay_Currency\Helpers\YayCurrencyHelper;
// 15.1 When a user is logged in, they are forced to use a custom currency; when the user is not logged in, the current currency is used.
add_filter('yay_currency_apply_currency', 'custom_yay_currency_apply_currency', 10, 1 );
function custom_yay_currency_apply_currency( $current_currency ) {
if ( !is_user_logged_in() ) {
return $current_currency;
}
$custom_currency_code = 'EUR';
$custom_current_currency = YayCurrencyHelper::get_currency_by_currency_code( $custom_currency_code );
return $custom_current_currency ? $custom_current_currency : $current_currency;
}
// 15.2 Custom current currency with Multiple Language plugins
usage:
use Yay_Currency\Helpers\YayCurrencyHelper;
// 15.2.1 Polylang and TranslatePress:
add_action( 'yay_currency_apply_currency', 'yay_currency_custom_current_currency' );
function yay_currency_custom_current_currency( $current_currency ) {
$currency_code = $current_currency['currency'];
$current_lang = get_locale(); // get current language
switch ($current_lang) {
case 'en_US':
$currency_code = 'USD';
break;
case 'en_GB':
$currency_code = 'GBP';
break;
case 'it_IT':
$currency_code = 'EUR';
break;
default:
break;
}
$custom_current_currency = YayCurrencyHelper::get_currency_by_currency_code( $currency_code );
return $custom_current_currency ? $custom_current_currency : $current_currency;
}
// 15.2.2 GTranslate
add_action( 'yay_currency_apply_currency', 'yay_currency_custom_current_currency' );
function yay_currency_custom_current_currency( $current_currency ) {
$currency_code = $current_currency['currency'];
$current_lang = isset($_SERVER['HTTP_X_GT_LANG']) ? $_SERVER['HTTP_X_GT_LANG'] : ''; // get current language
switch ($current_lang) {
case 'en_US':
$currency_code = 'USD';
break;
case 'en_GB':
$currency_code = 'GBP';
break;
case 'it_IT':
$currency_code = 'EUR';
break;
default:
break;
}
$custom_current_currency = YayCurrencyHelper::get_currency_by_currency_code( $currency_code );
return $custom_current_currency ? $custom_current_currency : $current_currency;
}
// 15.2.3 qTranslate X integration
add_action( 'yay_currency_apply_currency', 'yay_currency_custom_current_currency' );
function yay_currency_custom_current_currency( $current_currency ) {
$currency_code = $current_currency['currency'];
if ( function_exists('qtranxf_getLanguage') ) {
$current_lang = qtranxf_getLanguage(); // get current language
switch ($current_lang) {
case 'en_US':
$currency_code = 'USD';
break;
case 'en_GB':
$currency_code = 'GBP';
break;
case 'it_IT':
$currency_code = 'EUR';
break;
default:
break;
}
}
$custom_current_currency = YayCurrencyHelper::get_currency_by_currency_code( $currency_code );
return $custom_current_currency ? $custom_current_currency : $apply_currency;
}
//NOTE: WPML and Polylang (or other multiple languages plugins) function similarly to the above...
Customize the currency code: yay_currency_woocommerce_currency
usage:
add_filter( 'yay_currency_woocommerce_currency', array( $this, 'custom_currency_code' ), 10, 2 );
function custom_currency_code( $currency_code, $is_dis_checkout_diff_currency ) {
//... Your condition here .../
return $currency_code;
}
Customize the currency symbol: yay_currency_woocommerce_currency_symbol
usage:
add_filter( 'yay_currency_woocommerce_currency_symbol', array( $this, 'custom_currency_symbol' ), 10, 2 );
function custom_currency_symbol( $currency_symbol, $currency, $current_currency ) {
//... Your condition here .../
return $currency_symbol;
}
Customize the price format: yay_currency_custom_price_format
usage:
add_filter( 'yay_currency_custom_price_format', array( $this, 'custom_price_format' ), 10, 2 );
function custom_price_format( $format, $apply_currency ) {
//... Your condition here .../
return $format;
}
Customize product prices based on the current currency: yay_currency_get_price_by_currency
usage:
add_filter( 'yay_currency_get_price_by_currency', array( $this, 'custom_price_by_currency' ), 10, 3 );
public function custom_price_by_currency( $current_price, $product, $current_currency ) {
//... Your condition here .../
return $current_price;
}
Added:
yay_currency_by_country_code
andyay_currency_by_billing_country_code
are filter hooks to retrieve the currency based on the country code. (Pro version only)
$country_code = 'CA';
$currency_by_country_code = apply_filters( 'yay_currency_by_country_code', $country_code );
// get currency code, currency symbol,...
$currency_code = $currency_by_country_code['currency'];
$currency_symbol = $currency_by_country_code['symbol'];
$currency_by_user_billing_contry_code = apply_filters( 'yay_currency_by_billing_country_code', '' );
// get currency code, currency symbol,...
$currency_code = $currency_by_user_billing_contry_code['currency'];
$currency_symbol = $currency_by_user_billing_contry_code['symbol'];
Added:
yay_currency_convert_price
andyay_currency_revert_price
are filter hooks to convert prices to the current currency and revert them to the default currency.
$price = 99;
// get convert price by current currency
$convert_price = apply_filters('yay_currency_convert_price', $price );
// get convert price by specific currency
$currency_code = 'USD';
$apply_currency = \Yay_Currency\Helpers\YayCurrencyHelper::get_currency_by_currency_code( $currency_code );
$convert_price = apply_filters( 'yay_currency_convert_price', $price, $apply_currency );
$price = 99;
//Revert the price to the default currency (store currency)
$currency_code = 'EUR';
$apply_currency = \Yay_Currency\Helpers\YayCurrencyHelper::get_currency_by_currency_code( $currency_code );
$revert_price = apply_filters('yay_currency_revert_price', $price, $apply_currency );
Added:
yay_currency_product_price_with_caching
filter hook support for the caching option. (Pro version only)
// usage
add_filter('yay_currency_product_price_with_caching', 'yay_currency_custom_product_price_with_caching', 10, 2 );
function yay_currency_custom_product_price_with_caching( $price, $product ) {
// your conditions here (calculate product price)
......
//
return $price;
}
Last updated
Was this helpful?