Russian Post and EMS for WooCommerce Shortcode

Below, you’ll find a detailed guide on how to add the Russian Post and EMS for WooCommerce Shortcode to your WordPress website, including its parameters, examples, and PHP function code. Additionally, we’ll assist you with common issues that might cause the Russian Post and EMS for WooCommerce Plugin shortcode not to show or not to work correctly.

Before starting, here is an overview of the Russian Post and EMS for WooCommerce Plugin and the shortcodes it provides:

Plugin Icon
Russian Post and EMS for WooCommerce

"Russian Post and EMS for WooCommerce is a user-friendly plugin that seamlessly integrates Russian Post and EMS shipping methods into your WooCommerce store, ensuring efficient delivery options."

★★★★✩ (32) Active Installs: 2000+ Tested with: 5.8.8 PHP Version: 7.0
Included Shortcodes:
  • [fee]

Russian Post and EMS for WooCommerce [fee] Shortcode

The Russian Post and EMS for WooCommerce plugin shortcode ‘fee’ calculates and returns a dynamic fee based on set parameters. The ‘fee’ shortcode takes three parameters: percent, min_fee, and max_fee. It first calculates the fee as a percentage of a base cost. If the calculated fee is less than min_fee, it returns min_fee. If more than max_fee, it returns max_fee.

Shortcode: [fee]

Parameters

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

  • percent – defines the percentage of the fee cost
  • min_fee – sets the minimum fee value
  • max_fee – establishes the maximum fee value

Examples and Usage

Basic Example – A simple usage of the shortcode with the ‘percent’ parameter.

[fee percent="10" /]

This shortcode will calculate the fee as 10% of the base fee cost. If the base fee cost is $100, the calculated fee will be $10.

Advanced Examples

Example 1: Using the shortcode with ‘percent’ and ‘min_fee’ parameters.

[fee percent="10" min_fee="15" /]

In this case, the calculated fee will be the greater between 10% of the base fee cost and the minimum fee of $15. If the 10% of the base fee cost is less than $15, the calculated fee will be $15.

Example 2: Using the shortcode with ‘percent’, ‘min_fee’, and ‘max_fee’ parameters.

[fee percent="10" min_fee="15" max_fee="30" /]

Here, the calculated fee will be the greater between 10% of the base fee cost and the minimum fee of $15, but it will not exceed the maximum fee of $30. If the 10% of the base fee cost is less than $15, the calculated fee will be $15. If the 10% of the base fee cost is more than $30, the calculated fee will be $30.

PHP Function Code

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

Shortcode line:

add_shortcode( 'fee', array( $this, 'fee' ) );

Shortcode PHP function:

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

		$calculated_fee = 0;

		if ( $atts['percent'] ) {
			$calculated_fee = $this->fee_cost * ( floatval( $atts['percent'] ) / 100 );
		}

		if ( $atts['min_fee'] && $calculated_fee < $atts['min_fee'] ) {
			$calculated_fee = $atts['min_fee'];
		}

		if ( $atts['max_fee'] && $calculated_fee > $atts['max_fee'] ) {
			$calculated_fee = $atts['max_fee'];
		}

		return $calculated_fee;
	}

Code file location:

russian-post-and-ems-for-woocommerce/russian-post-and-ems-for-woocommerce/inc/class-rpaefw-shipping-method.php

Conclusion

Now that you’ve learned how to embed the Russian Post and EMS for WooCommerce Plugin shortcode, 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 *