I want to switch between two currency symbols on a Woocommerce product depending on what the user selects on a specific ACF field. Site is a real estate catalogue, there is no monetary transactions so I just need to change the symbol before the price.
I need it to display the default "$" or the custom "US$" prefix symbol but I can't make it work. Here is my code:
if ( ! function_exists( 'cambiar_currency_symbol' ) ) {
function cambiar_currency_symbol( $currency_symbol, $currency ) {
$currencyfield = get_field('moneda');
if $currencyfield = ('Currency1') {
switch ( $currency ) {
$currency_symbol = 'US$'; break;
}
}
return $currency_symbol;
}
add_filter( 'woocommerce_currency_symbol', 'cambiar_currency_symbol', 10, 2 );
}
Any idea what I'm missing?
Solved it by replacing the currency symbol all together with a custom option inside an ACF radio button:
function cambiar_currency_symbol( $currency_symbol, $currency ) {
$currencyacffield = get_field('moneda');
switch ( $currency ) {
case 'USD': $currency_symbol = $currencyacffield; break;
}
return $currency_symbol;
}
add_filter( 'woocommerce_currency_symbol', 'cambiar_currency_symbol', 10, 2 );
Tested and working.