Displaying currency switcher#

You can place one or more currency switchers on your website. You can also mix various methods to display them.

Using widget#

To insert Currency Switcher widget on your page, go to Appearance > Widgets section of your WordPress Admin dashboard. In Available Widgets area you should see Currency Switcher widget. Drag it to one of the sections on the right - for example Primary Sidebar. In widget settings you can modify its title. You can also leave title empty - that way it will not appear above your widget.


Using shortcode#

The shortcode to display Currency Switcher is [wcumcs_switcher]

Shortcode takes no attributes.

Insert this shortcode on any of your posts or pages and it will be converted to a currency switcher.

WCUMCS stands for WooCommerce Ultimate Multi Currency Suite :-)


Using PHP#

You can display switcher anywhere in your theme (or plugin) with a PHP code by calling one simple function. The function is: wcumcs_switcher();

Function documentation#

  • Usage
<?php wcumcs_switcher( $shortcode_atts, $shortcode_content ); ?>
  • Parameters

    • $shortcode_atts

      (string) (optional) Attributes of the shortcode

      Default: null

    • $shortcode_content

      (string) (optional) Content of the shortcode

      Default: null

  • Return Values

    • If no parameters are passed to the function - function echoes the switcher html code (echo $currency_switcher_html;) and returns true (bool)

    • If parameters are passed to the function - function returns the switcher html code (string) - return $currency_switcher_html;

  • Practical usage

    • If you want to just display (echo) the currency switcher, call the function without any parameters, like this:

      <?php wcumcs_switcher(); ?>

      This way the switcher will be displayed using echo and the function will return true.

    • If you want to get the currency switcher HTML code (have the function return it), call the function with a parameter (empty string), like this:

      <?php wcumcs_switcher(''); ?>

      This way the switcher HTML code will be returned by the function (as a string) without displaying (echoing) it.

    The reason to this function usage is the fact that the same PHP function is used for the WordPress shortcode and for the widget. The widget needs to have the HTML code displayed (echo $string;), while the shortcode needs to have the HTML code returned (return $string;). Function call by a shortcode always supplies function parameter(s) (even if it is just an empty string - in this case empty shortcode attributes list) - that's how we know that the function has been called by shortcode and we can return the HTML code instead of displaying it. Otherwise (no function parameters supplied) - the function will display the HTML code by echoing it.

Note

You can modify the switchers using the wcumcs_currency_switcher_output_html filter. Read more about how to do it in WordPress filters section.