Skip to content

Instantly share code, notes, and snippets.

@bekarice
Last active May 30, 2020 15:09
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 bekarice/17238f1fe1651aa17410 to your computer and use it in GitHub Desktop.
Save bekarice/17238f1fe1651aa17410 to your computer and use it in GitHub Desktop.
Change or Remove WooCommerce currency symbol + currency symbols for other plugins
/**
* These snippets can alter or remove currency symbols from several eCommerce plugins
* They are not made to be used together! I didn't feel like creating 1MM gists :)
* Tutorial: http://www.sellwithwp.com/pricing-remove-currency-symbol/
**/
/**
* WooCommerce
**/
// Remove all currency symbols
function sww_remove_wc_currency_symbols( $currency_symbol, $currency ) {
$currency_symbol = '';
return $currency_symbol;
}
add_filter('woocommerce_currency_symbol', 'sww_remove_wc_currency_symbols', 10, 2);
// Change the US currency symbol
function sww_change_wc_currency_symbol( $currency_symbol, $currency ) {
switch( $currency ) {
case 'USD': $currency_symbol = 'USD'; break;
// Can use this for any currency symbol
// ref https://github.com/woothemes/woocommerce/blob/master/includes/wc-core-functions.php#L314
}
return $currency_symbol;
}
add_filter('woocommerce_currency_symbol', 'sww_change_wc_currency_symbol', 10, 2);
/**
* Easy Digital Downloads
**/
// Removes currency symbol from the shop price display
function sww_remove_edd_currency_symbol( $output, $currency, $price ) {
$output = $price;
return $output;
}
// This will apply to USD, but the usd in this filter can be replaced with your currency symbol
// ref https://github.com/easydigitaldownloads/Easy-Digital-Downloads/blob/master/includes/formatting.php#L123
add_filter( 'edd_usd_currency_filter_before', 'sww_remove_edd_currency_symbol', 10, 3 );
// Changes currency symbol from the shop price display
function sww_change_edd_currency_symbol( $output, $currency, $price ) {
$output = 'USD ' . $price;
return $output;
}
// This will apply to USD, but the usd in this filter can be replaced with your currency symbol
add_filter( 'edd_usd_currency_filter_before', 'sww_change_edd_currency_symbol', 10, 3 );
/**
* WP eCommerce
**/
// Removes the currency symbol from the shop
function sww_change_wpec_currency_code( $args ) {
$args['display_currency_symbol'] = false;
return $args;
}
add_filter( 'wpsc_toggle_display_currency_code', 'sww_change_wpec_currency_code' );
/**
* Jigoshop
**/
// Changes currency symbol to USD
function sww_change_jigoshop_currency( $symbol ) {
return 'USD ';
}
add_filter( 'jigoshop_currency_symbol', 'sww_change_jigoshop_currency' );
// Removes currency symbol
function sww_remove_jigoshop_currency( $symbol ) {
return '';
}
add_filter( 'jigoshop_currency_symbol', 'sww_remove_jigoshop_currency' );
/**
* Shopp
**/
// Changes currency symbol to USD
function sww_change_shopp_currency_format( $format ) {
$format['currency'] = 'USD ';
return $format;
}
add_filter( 'shopp_money_format', 'sww_change_shopp_currency_format' );
// Removes currency symbol
function sww_remove_shopp_currency_format( $format ) {
$format['currency'] = '';
return $format;
}
add_filter( 'shopp_money_format', 'sww_remove_shopp_currency_format' );
/**
* Exchange
**/
// Changes currency symbol to USD
function sww_change_exchange_currency( $symbol ) {
return 'USD ';
}
add_filter( 'it_exchange_get_currency_symbol', 'sww_change_exchange_currency' );
// Removes Exchange currency symbol
function sww_remove_exchange_currency( $symbol ) {
return '';
}
add_filter( 'it_exchange_get_currency_symbol', 'sww_remove_exchange_currency' );
@norchris
Copy link

norchris commented Mar 6, 2020

Hi! This is my first comment ever on Github. I hope I am doing this the correct way and that you can help somehow.

In Woocommerce, I want to do something in addition to your code for selected product categories

  1. Remove currency symbol
  2. Multiple presentation of price by 100 (not actual price, only presentation - not the actual price (the issue is comparable to wanting to show a price in cents, not in dollars. In Norwegian terms; wanting to show price in "øre" [equivalent to cents], not in "kr" [equivalent to US$]

At the moment, I show in "kr" with a php code showing three decimals (but, for this product, people are use to refer to "øre") (please note that the text behind the price is set for each product with help form a plugin)
• on the page https://www.hurumkraft.no/billig-strom/
• with help of the following code
//from stackoverflow.com/questions/45424141/custom-decimals-in-woocommerce-product-prices-for-a-product-category
add_filter( 'wc_get_price_decimals', 'custom_price_decimals', 10, 1 );
function custom_price_decimals( $decimals ){
global $product;

if( is_a( $product, 'WC_Product' ) ){
    // Only for a defined product category
    if( has_term( 'stromprodukter', 'product_cat', $product->get_id() ) )
        $decimals = 3;
    if( has_term( 'bedriftsstrom', 'product_cat', $product->get_id() ) )
        $decimals = 3;
    if( has_term( 'billigstrom', 'product_cat', $product->get_id() ) )
        $decimals = 3;
    if( has_term( 'billigfastpris', 'product_cat', $product->get_id() ) )
        $decimals = 3;
    if( has_term( 'lavpris-strom-no1-no2', 'product_cat', $product->get_id() ) )
        $decimals = 3;
}
return $decimals;

}

Please help :-)

Norchris

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