The wc_price function solves your WooCommerce price formatting problems. Using it means you can ignore the WooCommerce price settings.
When you work on WooCommerce customization in your plugin/code snippet, you often need to format a price in order to display it correctly on the front-end.
Unfortunately, this can get tricky: you need to get (from the store settings) the WooCommerce currency symbol, the number of decimals, the decimal separator, the suffix, and so on. “Rebuilding” the price format each time can be really time-consuming.
Developers; please meet wc_price
.
This neat WooCommerce function can finally solve your price formatting nightmares and make you completely forget about the WooCommerce price settings: it’ll do the job for you.
As usual, we’ll take a look at practical examples; but first, let’s analyze the function code.