I am having some issues with the get_option
method in Wordpress.
I'm running a WooCommerce website and for the currency symbol position
is set to "Right with space". In the wp_options table the option_name
"woocommerce_currency_pos" is correctly set to "right_space".
When viewing products on the normal website, all works well, the currency code is displayed on the right and the option value is coming back correct.
The issue however is that we use a little JS function to show the cart (mini_cart.php
) in a lightbox and the code that is returned shows the currency code on the left.
After a bit of debugging I found the method get_woocommerce_price_format
and the first line here is: $currency_pos = get_option( 'woocommerce_currency_pos' );
So this is just a default function to get the value of the stated option_name
from the options table. This however returns "left" in this Ajax call.
I can't figure out how on earth, this is returning a different value than that in the database.
Obvious potential issues:
- Ajax is calling the wrong domain/website - But this is not happening, it is in the same project, the same code. Changes to the code reflect fine (a
die($currency_pos)
returns the string) - It's pulling from another database - There is only 1 for the project and 1 set of config settings, so it's almost impossible that it's getting this data from elsewhere (I only have 1 project with WooCommerce).
What could this weird issue be?
p.s.
The AJAX is called via /wp-admin/admin-ajax.php
This is the full function, it is not part of a class or anything
/**
* Get the price format depending on the currency position
*
* @return string
*/
function get_woocommerce_price_format ()
{
$currency_pos = get_option('woocommerce_currency_pos');
switch ($currency_pos) {
case 'left' :
$format = '%1$s%2$s';
break;
case 'right' :
$format = '%2$s%1$s';
break;
case 'left_space' :
$format = '%1$s %2$s';
break;
case 'right_space' :
$format = '%2$s %1$s';
break;
}
//$format = '%2$s %1$s';
return apply_filters('woocommerce_price_format', $format, $currency_pos);
}
if
)? There may be a default value somewhere that is being set and the code above could be ignored - but that's just a guess without more code.die($currency_pos)
directly below the line$currency_pos = get_option('woocommerce_currency_pos');
and it is returningleft
?