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
#2699426

Christopher Amirian
Supporter

Languages: English (English )

The test will confirm the problem is PHP 8 and then we will try to check if there is something with the custom function code.

#2699463

I just setup a very basic website. I created 3 custom fields - Brand, Model, and Price. I added 3 Pianos using the 3 fields. Then created a VIEW at:

hidden link

You can see the function works and produces the desired output. Price: $ 11,999.00

I added the following function to the functions.php at the end of the file.

/*The Convert to Currency function */
function format_money( $atts ) {
extract( shortcode_atts( array(
'price' => '0'), $atts) );
return $price = number_format($price, 2);
}
add_shortcode('format_money', 'format_money');

Now if this were PHP 8.0.30 will it still work???

#2699644

Christopher Amirian
Supporter

Languages: English (English )

Hi there,

I moved the website to another server with PHP 8.1 and it works there too:

hidden link

You can login here:

hidden link

Thanks.

#2699681

Hi Christopher,
I believe my problem is solved. A problem is with the value being NULL in the price field on some of the product. I added a 4th piano with no price value in the test site and it crashed the page. In the Live site the Zero Values did not affect it. My guess is the later version of PHP had a problem with a zero value. My solution is to place a conditional if 0 or less than 1 on price.

#2699744

Christopher, Thank you for all your help in narrowing down what was happening.