How to make WooCommerce price listings 3 digits separated

はるるるr

This is a story from when I was creating an e-commerce website that combines WordPress and WooCommerce.

I was creating while customizing the original WooCommerce template, but I thought the price notation was a bit difficult to read...

I see! I immediately noticed that there was no comma separated by three digits each, but what? But wait? How do you make that display? What happened.

So, a memo for myself with such a memory of 3.

to your future self

See below

<pre class="prism line-numbers lang-php" data-lang="PHP"><?php echo number_format($price);/* $price changes in time */ ?>

Explanation of the number_format() function

Now, the number_format() function plays an important role in this price notation (or rather, this is the only one).

This is a standard PHP function for formatting numbers and displaying them in an easy-to-read manner.

In particular, the three-digit comma separation in the amount display greatly improves usability.

No, no, I will leave a notation with or without a comma for those of you who thought that it would not change with or without a comma. (There is no such thing as a correct answer)

¥123,456,789
¥123456789

number_format How to use the () function

The number_format() function formats the number and returns it as a string.

The basic usage is very simple.
For example, number_format (1000) returns the string "1,000".

summary

The number_format() function is a powerful tool that makes displaying numbers user-friendly when combining WordPress and WooCommerce.

It's very easy, so let's remember it (although I forgot)

おすすめ記事

お問い合わせ

WEB制作、動画制作、オンライン配信、SNS運用代行などお気軽にご相談、お問い合わせください。

お問い合わせはこちら