Price Based on Country for WooCommerce Shortcode

Below, you’ll find a detailed guide on how to add the Price Based on Country 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 Price Based on Country for WooCommerce Plugin shortcode not to show or not to work correctly.

Before starting, here is an overview of the Price Based on Country for WooCommerce Plugin and the shortcodes it provides:

Plugin Icon
Price Based on Country for WooCommerce

"Price Based on Country for WooCommerce is a vital plugin that allows you to set different product prices for different countries. Convenient for international e-commerce businesses."

★★★★☆ (239) Active Installs: 20000+ Tested with: 6.3.2 PHP Version: false
Included Shortcodes:
  • [wcpbc_country_selector]

Price Based on Country for WooCommerce [wcpbc_country_selector] Shortcode

The WooCommerce Product Price Based on Countries shortcode is used to add a country selector widget to your site. This shortcode allows you to customize the widget with options like ‘remove_other_countries’, ‘flag’, ‘other_countries_text’, and ‘title’. It also provides the ability to change the widget’s layout before and after it is displayed.

Shortcode: [wcpbc_country_selector]

Parameters

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

  • remove_other_countries – If set to true, it hides other countries from the selector.
  • flag – If set to 1, it shows country flags in the selector.
  • other_countries_text – Changes the default text for the ‘other countries’ option.
  • title – Allows to set a custom title for the country selector widget.

Examples and Usage

Basic example – A simple implementation of the shortcode for the WooCommerce Product Price Based on Countries plugin. This example will display a country selector widget without any flags and will not remove other countries from the list.

[wcpbc_country_selector /]

Advanced examples

Using the shortcode to display a country selector widget with flags and a custom title. This will enhance the user experience by providing visual cues and clear instructions.

[wcpbc_country_selector flag=1 title="Select your country" /]

Using the shortcode to display a country selector widget that removes other countries from the list and uses a custom text for the remaining countries. This can be useful for businesses that only operate in specific countries.

[wcpbc_country_selector remove_other_countries=true other_countries_text="We only ship to these countries" /]

Using the shortcode to display a country selector widget with all the available attributes. This provides the most customization and control over the widget’s display and functionality.

[wcpbc_country_selector remove_other_countries=true flag=1 other_countries_text="We only ship to these countries" title="Select your country" /]

PHP Function Code

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

Shortcode line:

add_shortcode( 'wcpbc_country_selector', array( __CLASS__, 'shortcode_country_selector' ) );

Shortcode PHP function:

function shortcode_country_selector( $atts ) {

		$atts = shortcode_atts(
			array(
				'remove_other_countries' => false,
				'flag'                   => 0,
				'other_countries_text'   => apply_filters( 'wcpbc_other_countries_text', __( 'Other countries', 'woocommerce-product-price-based-on-countries' ) ),
				'title'                  => '',
			),
			$atts,
			'wcpbc_country_selector'
		);

		ob_start();

		the_widget(
			'WCPBC_Widget_Country_Selector',
			$atts,
			array(
				'before_widget' => '',
				'after_widget'  => '',
			)
		);

		return ob_get_clean();
	}

Code file location:

woocommerce-product-price-based-on-countries/woocommerce-product-price-based-on-countries/includes/class-wcpbc-frontend.php

Conclusion

Now that you’ve learned how to embed the Price Based on Country 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 *