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?
Open the functions. Now, go to backend of the WordPress website, navigate to the WooCommerce tab and then Settings. Click the Currency drop down under Currency Options, you will see the newly added custom currency at the end of the dropdown. Select the newly added currency from here and save the settings.
function test() { if ( class_exists( 'WOOMULTI_CURRENCY_F_Data' ) ) { $currency_data_obj = new WOOMULTI_CURRENCY_F_Data(); $current_currency = $currency_data_obj->get_current_currency(); echo "Currency is: ".
You can insert shortcode [woocs] in any place of your site, even in the top menu. Design: graphically Currency Switcher can be represented in 3 different ways: drop-down, flags, side switcher. For each currency it is possible to set flag. Checkout: the customers are allowed to pay in their selected(preferred) currency.
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.
You should always price under wc_price function, it will automatically add currency symbol along with the default span of woo commerce
For ex.. $product_price = 60; echo wc_price($product_price);
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With