# 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**&#x20;

```
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: 

// 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 'da_DK':
            $currency_code = 'DKK';
            break;
        case 'sv_SE':
            $currency_code = 'SEK';
            break;
        case 'en_GB':
            $currency_code = 'GBP';
            break;
        default:
            $currency_code = 'EUR';
            break;
    }

    $custom_current_currency = $current_currency;
    if ( function_exists( 'Yay_Currency\\plugin_init' ) &&
	class_exists('Yay_Currency\Helpers\YayCurrencyHelper') &&
	method_exists( 'Yay_Currency\Helpers\YayCurrencyHelper', 'get_currency_by_currency_code' ) 
    ) {
        $custom_current_currency = \Yay_Currency\Helpers\YayCurrencyHelper::get_currency_by_currency_code( $currency_code );
    }

   
    return $custom_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 = $current_currency;
    if ( function_exists( 'Yay_Currency\\plugin_init' ) &&
	class_exists('Yay_Currency\Helpers\YayCurrencyHelper') &&
        method_exists( 'Yay_Currency\Helpers\YayCurrencyHelper', 'get_currency_by_currency_code' ) 
    ) {
        $custom_current_currency = \Yay_Currency\Helpers\YayCurrencyHelper::get_currency_by_currency_code( $currency_code );
    }

   
    return $custom_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 = $current_currency;
    if ( function_exists( 'Yay_Currency\\plugin_init' ) &&
	class_exists('Yay_Currency\Helpers\YayCurrencyHelper') &&
	method_exists( 'Yay_Currency\Helpers\YayCurrencyHelper', 'get_currency_by_currency_code' ) 
    ) {
        $custom_current_currency = \Yay_Currency\Helpers\YayCurrencyHelper::get_currency_by_currency_code( $currency_code );
    }

   
    return $custom_current_currency;
}

//NOTE: WPML and Polylang (or other multiple languages plugins) function similarly to the above...
```

#### **Customize the currency code: yay\_currency\_woocommerce\_currency**&#x20;

```
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**&#x20;

```
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**&#x20;

```
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` and `yay_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` and `yay_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;
}
```

#### **Change custom\_flag**

```
// add_filter('yay_currency_get_flag_url_by_currency_code','yay_currency_custom_flag_url_by_country_code',10, 2);
function yay_currency_custom_flag_url_by_country_code( $flag_url, $currency_code ) {
	if( 'XOF' !==  $currency_code ) {
		return $flag_url;
	}
	return 'https://wp.test/wp-content/uploads/2024/11/CFA-flag-scaled.jpg'; // Change your CFA flag URL address here.
}
```

#### **Added:** `yay_currency_will_not_round_shipping_cost` **filter hook to disable rounding of the shipping fee.**

```
// add_filter('yay_currency_will_not_round_shipping_cost', '__return_true');
```

#### **Added: filter hooks to allow custom currencies and change currency flags.**

```
ex: Add Crypto Currencies (Cardano & Solana) - YayCurrency

// Add Cardano & Solana currencies to WooCommerce Settings
add_filter( 'woocommerce_currencies', 'add_cryptocurrencies_to_woocommerce_currencies' );
add_filter( 'woocommerce_currency_symbols', 'add_cryptocurrencies_to_woocommerce_currency_symbols' );

function add_cryptocurrencies_to_woocommerce_currencies( $currencies ) {
    if ( ! isset( $currencies['SOL'] ) ) {
        $currencies['SOL'] = 'Solana';
    }
	if ( ! isset( $currencies['ADA'] ) ) {
        $currencies['ADA'] = 'Cardano';
    }
	
    return $currencies;
}

function add_cryptocurrencies_to_woocommerce_currency_symbols( $currency_symbols ) {
    if ( ! isset( $currency_symbols['SOL'] ) ) {
        $currency_symbols['SOL'] = 'sol'; // sol is symbol
    }
	if ( ! isset( $currency_symbols['ADA'] ) ) {
        $currency_symbols['ADA'] = 'ada'; // ada is symbol
    }
    return $currency_symbols;
}

// Apply Sol currency to YayCurrency list
add_filter('YayCurrency/Data/CountryCurrencyMaps', 'CountryCurrencyMaps', 10, 1 );
function CountryCurrencyMaps( $countries_code ) {
	if(!isset($countries_code['SOL'])) {
		$countries_code['SOL'] = 'sol'; // sol is country code
	}
	if(!isset($countries_code['ADA'])) {
		$countries_code['ADA'] = 'ada'; // ada is country code
	}
	return $countries_code;
}
// Change Flag Sol currency

add_filter('YayCurrency/Fallbacks/GetFlags', 'GetFlagsFallback', 10, 1 );
function GetFlagsFallback( $mappings ) {
	$mappings = array_merge( $mappings, array(
        'sol' => 'https://s2.coinmarketcap.com/static/img/coins/64x64/5426.png',
		'ada' => 'https://s2.coinmarketcap.com/static/img/coins/64x64/2010.png',
    ));
	return $mappings;
}
```

#### Show non-default currencies

```
// add_filter(
	'yay_currency_detect_current_currency',
	function ( $apply_currency ) {
		if ( is_admin() && ! wp_doing_ajax() ) {
			return $apply_currency;
		}
		if ( ! class_exists( '\Yay_Currency\Helpers\YayCurrencyHelper' ) ) {
			return $apply_currency;
		}
		$bob = \Yay_Currency\Helpers\YayCurrencyHelper::get_currency_by_currency_code( 'BOB' );
		return ( is_array( $bob ) && ! empty( $bob['currency'] ) ) ? $bob : $apply_currency;
	},
	20
);
```


---

# Agent Instructions: Querying This Documentation

If you need additional information that is not directly available in this page, you can query the documentation dynamically by asking a question.

Perform an HTTP GET request on the current page URL with the `ask` query parameter:

```
GET https://docs.yaycommerce.com/yaycurrency/configurations/developer-zone/available-yaycurrency-hooks.md?ask=<question>
```

The question should be specific, self-contained, and written in natural language.
The response will contain a direct answer to the question and relevant excerpts and sources from the documentation.

Use this mechanism when the answer is not explicitly present in the current page, you need clarification or additional context, or you want to retrieve related documentation sections.
