Skip Navigation

[Resolved] How can I add thousand separator in toolset classifieds site prices?

This thread is resolved. Here is a description of the problem and solution.

Problem:

The essence of this thread is to ask if it is possible to have a number separator for the number fields, example having 1000 in the format 1,000 with a comma as a separator

Solution:

Unfortunately not, since the number field can only handle numbers and no string elements then it is not possible natively.

However through some javascript this becomes possible, this means that the javascript will reformat the strings for you on the frontend.

You simply need to add this code that the customer shared to your view javascript section.

function numberWithCommas(x) {
return x.toString().replace(/\B(?=(?:\d{3})+(?!\d))/g, ",");
}
$('.price').each(function(){
var v_pound = $(this).html();
v_pound = numberWithCommas(v_pound);

$(this).html(v_pound)

})

100% of people find this useful.

This support ticket is created 8 years ago. There's a good chance that you are reading advice that it now obsolete.

This is the technical support forum for Toolset - a suite of plugins for developing WordPress sites without writing PHP.

Everyone can read this forum, but only Toolset clients can post in it. Toolset support works 6 days per week, 19 hours per day.

Sun Mon Tue Wed Thu Fri Sat
- 9:00 – 12:00 9:00 – 12:00 9:00 – 12:00 9:00 – 12:00 9:00 – 12:00 -
- 13:00 – 18:00 13:00 – 18:00 13:00 – 18:00 14:00 – 18:00 13:00 – 18:00 -

Supporter timezone: America/Jamaica (GMT-05:00)

This topic contains 6 replies, has 2 voices.

Last updated by SadeghH4619 8 years ago.

Assisted by: Shane.

Author
Posts
#382188

Hi
Please tell me how can I add thousand separator in toolset classifieds site prices?
Thanks

#382202

Shane
Supporter

Languages: English (English )

Timezone: America/Jamaica (GMT-05:00)

Hi Sadegh,

When you refer to thousand separator I believe you are talking about the prices correct ?

If so then this can be done by going to Woocommerce -> Settings and then scrolling to the currency options.

Please let me know if this helps.
Thanks,
Shane

#382300
Without Thousand Separator.JPG
Thousand Separator.JPG

Hi Shane,
Yes I'm talking about ads prices.
That setting doesn't work on ads.
I've attached two screenshots so as you can see it doesn't work on ads.
Thanks

#383664

Shane
Supporter

Languages: English (English )

Timezone: America/Jamaica (GMT-05:00)

Hi Sadegh,

These fields are actually numeric fields and can't handle string type number separators.

To allow for this you will need to change the field type to a single line field in your Types custom field settings.

This should allow you to add your separators but it would need to be done manually.

Please let me know if this helps.
Thanks,
Shane

#384509

Hi Shane,
"This should allow you to add your separators but it would need to be done manually."
It means users have to add separators?
If I'm right, Please tell me is there any way to add separators automatically?
Thanks

#385515

Shane
Supporter

Languages: English (English )

Timezone: America/Jamaica (GMT-05:00)

Hi Sadegh,

Yes this means that the users will need to add the separator when they are entering the price value.

Adding the separator automatically will require that you modify the custom field code or create a hook to do this.

Such custom coding is out of the scope of our support forum as our native API and interfaces do not support this 🙁

So i'm not able to assist much with this one.

Thanks,
Shane

#387718

Hi
I've found a solution that works greatly:
adding this jQuery code to the site will solve this issue:

function numberWithCommas(x) {
return x.toString().replace(/\B(?=(?:\d{3})+(?!\d))/g, ",");
}
$('.price').each(function(){
var v_pound = $(this).html();
v_pound = numberWithCommas(v_pound);

$(this).html(v_pound)

})

This ticket is now closed. If you're a WPML client and need related help, please open a new support ticket.