I am developing an extension for woocommerce WordPress plugin.
I would like to display the currency symbol outside of the loop in a custom function
I have the following:
function my_function( ) {
global $woocommerce;
echo get_woocommerce_currency_symbol();
}
I am not sure why but this doesn't output the symbol? Am I missing something?
Your code should work, which means the issue might be in the database. You can check these 2 functions:
get_woocommerce_currency() and get_woocommerce_currency_symbol()
from the WooCommerce docs that shows that you are using the functions correct.
What is left is for you to start some troubleshooting steps to see what causes the error:
What is get_option('woocommerce_currency')
returning? If nothing, then you have no currency set and that is why you get nothing from get_woocommerce_currency_symbol();
What happens if you add a currency as a parameter to get_woocommerce_currency_symbol
? it gets displayed? something like echo get_woocommerce_currency_symbol("USD");
You should add to your script some error handling lines, to inform the user that he needs to have the currency set before using your extension.