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;
}
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).
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
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;
}