Yaycurrency Shortcodes

Below, you’ll find a detailed guide on how to add the Yaycurrency Shortcodes to your WordPress website, including their parameters, examples, and PHP function code. Additionally, we’ll assist you with common issues that might cause the Yaycurrency Plugin shortcodes not to show or not to work correctly.

Before starting, here is an overview of the Yaycurrency Plugin and the shortcodes it provides:

Plugin Icon
YayCurrency – WooCommerce Multi-Currency Switcher

"YayCurrency – WooCommerce Multi-Currency Switcher is a reliable plugin for WordPress that enables users to switch between different currencies on their WooCommerce platform, enhancing the shopping experience for international customers."

★★★★☆ (58) Active Installs: 3000+ Tested with: 6.3.2 PHP Version: 5.4
Included Shortcodes:
  • [yaycurrency-switcher]
  • [yaycurrency-menu-item-switcher]
  • [yaycurrency-price-html]
  • [yaycurrency-fee]
  • [yaycurrency-fee-default]

Yaycurrency [yaycurrency-switcher] Shortcode

The ‘yaycurrency-switcher’ shortcode is used to display a currency switcher on your WordPress site. It checks if the page is a checkout page, and if so, it returns an empty string. It fetches options for displaying flags, currency names, symbols, and codes in the switcher. The size of the switcher can be adjusted. It then includes a template for the switcher and returns its content.

Shortcode: [yaycurrency-switcher]

Examples and Usage

Basic Example – The following shortcode displays a currency switcher on your website. The switcher will not be displayed on the checkout page or the order received page. The shortcode will display the currency flag, name, symbol, and code by default, in a medium size.

[yaycurrency-switcher /]

Advanced Examples

Example 1: This shortcode displays a currency switcher without a currency flag. It sets the ‘yay_currency_show_flag_in_switcher’ option to 0, meaning the flag will not be shown.

[yaycurrency-switcher show_flag=0 /]

Example 2: This shortcode displays a currency switcher without a currency symbol. It sets the ‘yay_currency_show_currency_symbol_in_switcher’ option to 0, meaning the symbol will not be shown.

[yaycurrency-switcher show_symbol=0 /]

Example 3: This shortcode displays a large sized currency switcher. It sets the ‘yay_currency_switcher_size’ option to ‘large’.

[yaycurrency-switcher size='large' /]

Example 4: This shortcode displays a currency switcher with only the currency code. It sets the ‘yay_currency_show_currency_name_in_switcher’ and ‘yay_currency_show_currency_symbol_in_switcher’ options to 0, meaning the name and symbol will not be shown.

[yaycurrency-switcher show_name=0 show_symbol=0 /]

PHP Function Code

In case you have difficulties debugging what causing issues with [yaycurrency-switcher] shortcode, check below the related PHP functions code.

Shortcode line:

add_shortcode( 'yaycurrency-switcher', array( $this, 'currency_dropdown_shortcode' ) );

Shortcode PHP function:

function currency_dropdown_shortcode( $content = null ) {
		if ( is_checkout() && ( is_wc_endpoint_url( 'order-pay' ) || is_wc_endpoint_url( 'order-received' ) ) ) {
			return '';
		}
		$is_show_flag            = get_option( 'yay_currency_show_flag_in_switcher', 1 );
		$is_show_currency_name   = get_option( 'yay_currency_show_currency_name_in_switcher', 1 );
		$is_show_currency_symbol = get_option( 'yay_currency_show_currency_symbol_in_switcher', 1 );
		$is_show_currency_code   = get_option( 'yay_currency_show_currency_code_in_switcher', 1 );
		$switcher_size           = get_option( 'yay_currency_switcher_size', 'medium' );

		ob_start();
		require YAY_CURRENCY_PLUGIN_DIR . 'includes/templates/switcher/template.php';
		$content = ob_get_clean();
		return $content;

	}

Code file location:

yaycurrency/yaycurrency/includes/Engine/FEPages/Shortcodes.php

Yaycurrency [yaycurrency-menu-item-switcher] Shortcode

The ‘yaycurrency-menu-item-switcher’ shortcode is used to display a currency switcher in the menu. It checks if the page is a checkout page and if it is, it doesn’t display anything. It then fetches options for displaying flags, currency names, symbols, and codes. .

Shortcode: [yaycurrency-menu-item-switcher]

Examples and Usage

Basic example – A straightforward instance of using the shortcode ‘yaycurrency-menu-item-switcher’ to display the currency switcher in the menu. It does not require any parameters.

[yaycurrency-menu-item-switcher /]

Advanced examples – In the given PHP code, there are no parameters directly passed to the shortcode. Instead, the function ‘menu_item_switcher_shortcode’ uses the get_option function to get the option values from the WordPress database. These options are set in the WordPress admin dashboard, not directly in the shortcode. Therefore, the shortcode does not provide an example with multiple parameters.

However, the function does check whether the current page is a WooCommerce checkout page or not. If it is a checkout page, the function returns an empty string, and the currency switcher is not displayed. This is an example of how the function can be used to control where the currency switcher is displayed based on the page context.

Here is a theoretical example of how you might modify the function to accept parameters in the shortcode:


function menu_item_switcher_shortcode( $atts, $content = null ) {
	$atts = shortcode_atts( array(
		'show_flag' => 1,
		'show_currency_name' => 1,
		'show_currency_symbol' => 1,
		'show_currency_code' => 1,
		'switcher_size' => 'small',
	), $atts );

	// rest of the function...
}

With this modification, you could use the shortcode like this:

[yaycurrency-menu-item-switcher show_flag=0 show_currency_name=1 show_currency_symbol=0 show_currency_code=1 switcher_size="large" /]

This would display a large currency switcher in the menu, with the currency name and code, but without the flag or currency symbol.

PHP Function Code

In case you have difficulties debugging what causing issues with [yaycurrency-menu-item-switcher] shortcode, check below the related PHP functions code.

Shortcode line:

add_shortcode( 'yaycurrency-menu-item-switcher', array( $this, 'menu_item_switcher_shortcode' ) );

Shortcode PHP function:

function menu_item_switcher_shortcode( $content = null ) {
		if ( is_checkout() && ( is_wc_endpoint_url( 'order-pay' ) || is_wc_endpoint_url( 'order-received' ) ) ) {
			return '';
		}
		$is_show_flag            = get_option( 'yay_currency_show_flag_in_menu_item', 1 );
		$is_show_currency_name   = get_option( 'yay_currency_show_currency_name_in_menu_item', 1 );
		$is_show_currency_symbol = get_option( 'yay_currency_show_currency_symbol_in_menu_item', 1 );
		$is_show_currency_code   = get_option( 'yay_currency_show_currency_code_in_menu_item', 1 );
		$switcher_size           = get_option( 'yay_currency_menu_item_size', 'small' );

		ob_start();
		require YAY_CURRENCY_PLUGIN_DIR . 'includes/templates/switcher/template.php';
		$content = ob_get_clean();
		return $content;

	}

Code file location:

yaycurrency/yaycurrency/includes/Engine/FEPages/Shortcodes.php

Yaycurrency [yaycurrency-price-html] Shortcode

The YayCurrency plugin shortcode is designed to convert and display prices in different currencies. This shortcode, when applied, fetches the price value from the ‘price’ attribute. It then uses the ‘yaycurrency_get_price’ filter to retrieve the price. The current currency is detected using YayCurrencyHelper’s detect_current_currency() function. The price is then converted to the detected currency using the calculate_price_by_currency_html() function. The converted price is further processed with the ‘yaycurrency_get_price_html’ filter and displayed on the webpage.

Shortcode: [yaycurrency-price-html]

Parameters

Here is a list of all possible yaycurrency-price-html shortcode parameters and attributes:

  • price – The initial price value to be converted

Examples and Usage

Basic example – Showcasing the use of the ‘yaycurrency-price-html’ shortcode to display a price.

[yaycurrency-price-html price="100" /]

This shortcode will display a price of 100 in the current currency of the website. The ‘price’ attribute represents the price value you want to display.

Advanced examples

Utilizing the ‘yaycurrency-price-html’ shortcode to display a price, while also applying a filter to modify the displayed price.

add_filter('yaycurrency_get_price', function($price){
    return $price * 1.2; // Increase price by 20%
}, 10, 1);

[yaycurrency-price-html price="100" /]

In this advanced example, we have added a filter ‘yaycurrency_get_price’ which modifies the price before it is displayed. The price is increased by 20% in this case. Then, the ‘yaycurrency-price-html’ shortcode is used to display the modified price.

Another advanced example where we modify the displayed price’s HTML using a filter.

add_filter('yaycurrency_get_price_html', function($price_html, $currency){
    return '' . $price_html . ''; // Wrap price in a custom class
}, 10, 2);

[yaycurrency-price-html price="100" /]

In this example, we have added a filter ‘yaycurrency_get_price_html’ which modifies the HTML of the displayed price. The price is wrapped in a span with a custom class. Then, the ‘yaycurrency-price-html’ shortcode is used to display the modified price.

PHP Function Code

In case you have difficulties debugging what causing issues with [yaycurrency-price-html] shortcode, check below the related PHP functions code.

Shortcode line:

add_shortcode( 'yaycurrency-price-html', array( $this, 'yay_convert_price_html' ) );

Shortcode PHP function:

function yay_convert_price_html( $atts, $content = null ) {
		$atts = shortcode_atts(
			array(
				'price' => '',
			),
			$atts
		);

		ob_start();
		$price          = apply_filters( 'yaycurrency_get_price', $atts['price'] );
		$apply_currency = YayCurrencyHelper::detect_current_currency();
		$price_html     = YayCurrencyHelper::calculate_price_by_currency_html( $apply_currency, $price );
		$price_html     = apply_filters( 'yaycurrency_get_price_html', $price_html, $apply_currency );
		echo wp_kses_post( $price_html );
		return ob_get_clean();
	}

Code file location:

yaycurrency/yaycurrency/includes/Engine/FEPages/Shortcodes.php

Yaycurrency [yaycurrency-fee] Shortcode

The YayCurrency shortcode is a custom function that calculates fees based on a set percentage, minimum, and maximum fee in the user’s currency. It detects the user’s currency, applies it to the minimum and maximum fees, then calculates the final fee based on the cart subtotal.

Shortcode: [yaycurrency-fee]

Parameters

Here is a list of all possible yaycurrency-fee shortcode parameters and attributes:

  • percent – Determines the fee percentage for the currency.
  • min_fee – Sets the minimum fee value for the currency conversion.
  • max_fee – Defines the maximum fee limit for the currency conversion.

Examples and Usage

Basic example – A simple implementation of the ‘yaycurrency-fee’ shortcode. Here, we are specifying only the ‘percent’ attribute. This will calculate the fee based on the given percentage.

[yaycurrency-fee percent="5" /]

Advanced examples

Example 1 – In this example, we are specifying all three attributes: ‘percent’, ‘min_fee’, and ‘max_fee’. The fee will be calculated based on the given percentage, but it will not go below or above the specified minimum and maximum fees.

[yaycurrency-fee percent="10" min_fee="5" max_fee="50" /]

Example 2 – Here, we are specifying only the ‘min_fee’ and ‘max_fee’ attributes. This will calculate the fee based on the cart subtotal, ensuring that it does not go below or above the specified minimum and maximum fees.

[yaycurrency-fee min_fee="10" max_fee="100" /]

These examples demonstrate the flexibility of the ‘yaycurrency-fee’ shortcode and how it can be customized to suit various e-commerce scenarios.

PHP Function Code

In case you have difficulties debugging what causing issues with [yaycurrency-fee] shortcode, check below the related PHP functions code.

Shortcode line:

add_shortcode( 'yaycurrency-fee', array( $this, 'yay_currency_calculate_fee' ) );

Shortcode PHP function:

function yay_currency_calculate_fee( $atts ) {
		$atts = shortcode_atts(
			array(
				'percent' => '',
				'min_fee' => '',
				'max_fee' => '',
			),
			$atts,
			'yaycurrency-fee'
		);

		$apply_currency = YayCurrencyHelper::detect_current_currency();

		$atts['min_fee'] = YayCurrencyHelper::calculate_price_by_currency( $atts['min_fee'], true, $apply_currency );
		$atts['max_fee'] = YayCurrencyHelper::calculate_price_by_currency( $atts['max_fee'], true, $apply_currency );

		$cart_subtotal  = apply_filters( 'yay_currency_get_cart_subtotal', 0, $apply_currency );
		$calculated_fee = $this->get_fee_cost_by_shortcode( $cart_subtotal, $atts );

		return $calculated_fee;
	}

Code file location:

yaycurrency/yaycurrency/includes/Engine/FEPages/Shortcodes.php

Yaycurrency [yaycurrency-fee-default] Shortcode

The YayCurrency shortcode is a versatile tool that calculates a default fee based on cart subtotal. It allows customization with attributes like ‘percent’, ‘min_fee’, and ‘max_fee’. This shortcode applies to the cart subtotal, calculates the fee, and returns the result. This allows for dynamic fee adjustments based on user-specific conditions.

Shortcode: [yaycurrency-fee-default]

Parameters

Here is a list of all possible yaycurrency-fee-default shortcode parameters and attributes:

  • percent – The percentage of the cart subtotal to be calculated as a fee.
  • min_fee – The minimum fee amount that can be charged.
  • max_fee – The maximum fee amount that can be charged.

Examples and Usage

Basic example – The following shortcode calculates the default fee without specifying any parameters. By default, it will use the values set in the plugin settings.

[yaycurrency-fee-default /]

Advanced examples

1. Specifying a percentage fee: This shortcode calculates the fee based on a specified percentage of the cart subtotal. The ‘percent’ attribute is used to define the percentage fee.

[yaycurrency-fee-default percent=10 /]

2. Setting minimum and maximum fee limits: This shortcode calculates the fee based on the ‘percent’ attribute, but it will not go below the ‘min_fee’ or above the ‘max_fee’ values.

[yaycurrency-fee-default percent=10 min_fee=5 max_fee=50 /]

3. Using the shortcode with all parameters: This example calculates the fee based on the ‘percent’ attribute. It also sets minimum and maximum fee limits, ensuring the calculated fee will not go below or above these values. If the ‘percent’ attribute is not set, the plugin will use the default percentage set in the plugin settings.

[yaycurrency-fee-default percent=10 min_fee=5 max_fee=50 /]

PHP Function Code

In case you have difficulties debugging what causing issues with [yaycurrency-fee-default] shortcode, check below the related PHP functions code.

Shortcode line:

add_shortcode( 'yaycurrency-fee-default', array( $this, 'yay_currency_calculate_fee_default' ) );

Shortcode PHP function:

function yay_currency_calculate_fee_default( $atts ) {
		$atts = shortcode_atts(
			array(
				'percent' => '',
				'min_fee' => '',
				'max_fee' => '',
			),
			$atts,
			'yaycurrency-fee-default'
		);

		$cart_subtotal  = apply_filters( 'yay_currency_get_cart_subtotal_default', 0 );
		$calculated_fee = $this->get_fee_cost_by_shortcode( $cart_subtotal, $atts );

		return $calculated_fee;
	}

Code file location:

yaycurrency/yaycurrency/includes/Engine/FEPages/Shortcodes.php

Conclusion

Now that you’ve learned how to embed the Yaycurrency Plugin shortcodes, understood the parameters, and seen code examples, it’s easy to use and debug any issue that might cause it to ‘not work’. If you still have difficulties with it, don’t hesitate to leave a comment below.

Comments

Leave a Reply

Your email address will not be published. Required fields are marked *