Skip to content

Instantly share code, notes, and snippets.

@BFTrick
Last active December 14, 2023 00:01
Show Gist options
  • Star 4 You must be signed in to star a gist
  • Fork 2 You must be signed in to fork a gist
  • Save BFTrick/10681832 to your computer and use it in GitHub Desktop.
Save BFTrick/10681832 to your computer and use it in GitHub Desktop.
Display the currency symbol with the currency code first
<?php
/**
* Plugin Name: WooCommerce Display Currency Code in Currency Symbol
* Plugin URI: https://gist.github.com/BFTrick/10681832
* Description: Add the currency code to the currency symbol in WooCommerce. Ex. USD $.
* Author: Patrick Rauland
* Author URI: http://patrickrauland.com/
* Version: 1.0
*
* This program is free software: you can redistribute it and/or modify
* it under the terms of the GNU General Public License as published by
* the Free Software Foundation, either version 3 of the License, or
* (at your option) any later version.
*
* This program is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
* GNU General Public License for more details.
*
* You should have received a copy of the GNU General Public License
* along with this program. If not, see <http://www.gnu.org/licenses/>.
*
*/
function patricks_currency_symbol( $currency_symbol, $currency ) {
switch( $currency ) {
case 'USD':
$currency_symbol = 'USD $';
break;
case 'NZD':
$currency_symbol = 'NZD $';
break;
case 'AUD':
$currency_symbol = 'AUD $';
break;
}
return $currency_symbol;
}
add_filter('woocommerce_currency_symbol', 'patricks_currency_symbol', 30, 2);
@TomasHurtz
Copy link

Hello. I have issue with showing shortcode on two places (one in header and one in the Order section of checkout:

Get DOM error: [DOM] Found 2 elements with non-unique id #currency_switcher: (More info: https://goo.gl/9p2vKq)

Needs a unique select ID (php8)
This does not work:
https://stackoverflow.com/questions/26782642/unique-id-for-wordpress-shortcodes-when-used-more-than-once-on-a-page

Any ideas?

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment