# Available YayCurrency Hooks

You can add these hooks to variables in template.php to alter the data that generates the switcher.

1. **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;
}
```

2. **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;
}
```

3. **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;
}
```

4. **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;
}
```

5. **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;
}
```

6. **Added: filter hook hide dropdown/switcher in analytics**

```
add_filter('yay_currency_hide_dropdown_filter_analytics', '__return_true');
```

7. **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';
}
```

8. **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 );
```

9. **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 );
```

10. **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 );
```

11. **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 );
```

12. **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 );
```

13. **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 );
```

14. **Get the exchange rate for the current currency: yay\_currency\_rate**

```
usage: 
$rate_fee = apply_filters('yay_currency_rate',1);
```

15. **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...
```

16. **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;
}
```

17. **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;
}
```

18. **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;
}
```

19. **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;
}
```

20. **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'];
```

21. **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 );
```

22. **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;
}
```
