Skip Navigation

[Resolved] Convert numbers to currency in Block editor, old system used function that break

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.

This topic contains 18 replies, has 2 voices.

Last updated by tonyM-3 1 year, 3 months ago.

Assisted by: Christopher Amirian.

Author
Posts
#2698473

Tell us what you are trying to do? I am trying to use the new Toolset Blocks in wordpress to display currency converted from numbers. There are several post showing it done in the old editor using a function: but can not figure how to use it in the Blocks editor.

Is there any documentation that you are following? Can't find documentation for the blocks editor regarding currency.

Is there a similar example that we can see? in the old system I added a function to the functions.php file and used this in the old editor:
Price: $ [format_money price="[types field="used-price"][/types]"]<br>
#[types field='used-serial'][/types]

What is the link to your site? The following is a test site that I am testing new features. It is usually turned off, so to view it I must know when to activated the test site.
hidden link

#2698550

Christopher Amirian
Supporter

Languages: English (English )

Hi there,

You can not use the custom features on block editor, but you can use the same shortcode that you used to add in block editor by adding the "Fields and Text" block of Toolset and pasting the same code you used in the old editor.

Thanks.

#2698676

I tried what you suggested before I emailed you, I used "Fields and Text" and tried several different ways and all resulted in a crash of the page. I did test the page without the formating and it worked fine. Once I insert the date formatting it no longer worked. The code I used on the old page that worked for YEARS is:

<p><strong style="color:red !important; font-size:101%;">Sale Price: $[format_money price="[types field="sale-price"][/types]"]</p>

I also tried the cut down version:

Sale Price: $[format_money price="[types field="sale-price"][/types]"]

and it also crashed the page. What would be ideal would have a money formatter built in. Can you offer any other suggestions?

#2698679
Image 5-20-24 at 3.19 PM.jpeg

Following are screen shots of the error and the code.

#2698805

Christopher Amirian
Supporter

Languages: English (English )

Hi there,

There is no built in formatted, but the screenshot you have sent is correct and it shows the interpreted version of the types shortcode you used. that is a normal behavior. What happens on the front end? If it shows correctly then it is ok.

If not, I can take a look into the issue. I'd appreciate it if you could give me the URL/User/Pass of your WordPress dashboard after you make sure that you have a backup of your website.
It is absolutely important that you give us a guarantee that you have a backup so if something happens you will have a point of restore.

Make sure you set the next reply as private.

#2698845

The website is a development website pianodistributors.net. I have to activate it and get you access later. FYI this website is a digital ocean droplet. I set it up with Php 8.0 and latest Apache server. I did a full migration from the working website. I have been doing this sort of thing to test new programs before taking to my live site for several years. I actually have easy backups. I will be back with the password and log in in a bit
Tony

#2698873

I am leaving this website on and it is completely backed up.

#2698976

Christopher Amirian
Supporter

Languages: English (English )

Hi there,

Thanks. I set the reply you gave with the password private. Please do not add sensitive information without setting the reply as private.

I tried to access the view but unfortunately, I get this error:

Sorry, you are not allowed to access this page.

And I do not have access to Toolset menus and stuff. It seems the role you gave is not admin.

Please provide a user with admin role. and please make the next reply as private if you want to provide new password and user.

Thanks.

#2699002

I replied to this an hour ago, It seems to be deleted.

#2699217

The test site PianoDistributors.net is on an Ubuntu server running Apache2 with PHP8.X the live site PianoDistributors.com is PHP7.4. Is it possible the code used to format to currency display may not work with the newer PHP? By the way, I do not see here how to convert to private.

#2699284

I have narrowed down the problem to not just the new block editor but also in the classic.
1. the full function breaks the page: [format_money price="[types field="used-price"][/types]"]
2. I can separate the [format_money price="1234"][/types]"] works
3. The [types field="used-price"][/types] works

It seems the error is caused by the combo of the 2:
ERROR FILE SHOWS:
[Fri May 24 04:35:23.667276 2024] [php:error] [pid 17806] [client 207.46.13.127:42038] PHP Fatal error: Uncaught TypeError: number_format(): Argument #1 ($num) must be of type float, string given in /var/www/html/wp-content/themes/sydney-child/functions.php:43\nStack trace:\n#0 /var/www/html/wp-content/themes/sydney-child/functions.php(43): number_format()\n#1 .......

#2699349

Christopher Amirian
Supporter

Languages: English (English )

Hi there,

I tried to double-check and unfortunately, now the user pass does not work. But the fact that you mentioned in the last reply gave me a hint that you need to register the custom shortcodes in Toolset.

Please go to WordPress Dashboard > Toolset > Settings> Front end Content (tab).

Add the shortcode you used in "Third-party shortcode arguments" section.

Thanks.

#2699401

I have turned the site off for now. I will return to this later next week. This problem has not changed at all. It all boils down to this: The old live site works fine, It is not registered in custom shortcodes in Toolset, but works anyway.

On the Test Site, $ [format_money price="[types field="used-price"][/types]"] function has not worked since upgrading the PHP and will crash the page containing the function.
The main difference between the live site and the test site is the live site uses PHP 7.4 and the Test Site uses PHP 8.0.30

I have used this function for several years with no problems. I just spun up a new server and used the new PHP 8.0.30 for testing. The whole web site appears to be working fine except for this one issue. I believe there is a conflict between the Type variable and the function while in PHP 8.0.30. It is either a glitch in the TOOLSET when in PHP 8.0.30 or the function itself has a bug while in PHP 8.0.30. Just keep in mind the function works fine by itself, eg. $ [format_money price="12345"] returns this -> $ 12,345.00
and Price: $ [types field='used-price'][/types]<br> returns the price like: $8999

#2699413

Christopher Amirian
Supporter

Languages: English (English )

Hi there,

Thank you for the information. Actually, it can be tested on our server as it uses PHP version 7.4.

Do you think you can use the function there and tell us if it works there? (Use the link below to login)

hidden link

Thanks.

#2699418

I can do that, but so far it works on PHP version 7.4. Only a problem with PHP version 8