I want to display a custom currency symbol based on product category. I took the following snippet suggested on this question Change currency symbol based on product category in Woocommerce.
However I actually need the custom currency to be displayed also in all Woocommerce pages (including cart and checkout page).
This is my code:
add_filter('woocommerce_currency_symbol', 'change_existing_currency_symbol', 10, 2);
function change_existing_currency_symbol( $currency_symbol, $currency ) {
global $post, $product, $woocommerce;
if ( has_term( 'cupones', 'product_cat' ) ) :
switch( $currency ) {
case 'EUR': $currency_symbol = 'ptos'; break;
}
return $currency_symbol;
elseif ( has_term( 'cupones', 'product_cat' ) && is_cart() ):
switch( $currency ) {
case 'EUR': $currency_symbol = 'ptos'; break;
}
return $currency_symbol;
elseif ( has_term( 'cupones', 'product_cat' ) && is_checkout() ):
switch( $currency ) {
case 'EUR': $currency_symbol = 'ptos'; break;
}
return $currency_symbol;
endif;
}
Updated: For cart and checkout pages, there is 2 ways: By item or globally.
1) BY ITEM (The most complicated):
2) GLOBALLY (Much more easier):
The following code based on your code settings will change the currency symbol globally on cart and on checkout pages too, When 'cupones' product category is found in any cart item:
Code goes in function.php file of your active child theme (or active theme). Tested and works.