Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

woocommerce get_woocommerce_currency_symbol()

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?

like image 834
danyo Avatar asked Aug 21 '13 18:08

danyo


People also ask

How do I get the price symbol in WooCommerce?

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.

How can I get current currency in WordPress?

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: ".

How do I use currency switcher in WooCommerce?

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.


Video Answer


2 Answers

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.

like image 85
jnhghy - Alexandru Jantea Avatar answered Oct 03 '22 01:10

jnhghy - Alexandru Jantea


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); 
like image 40
MakeWebBetter Avatar answered Oct 03 '22 00:10

MakeWebBetter