Saltar navegación

[Resuelto] 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.

Este tema contiene 18 respuestas, tiene 2 mensajes.

Última actualización por tonyM-3 2 years ago.

Asistido por: Christopher Amirian.

Autor
Mensajes
#2699426

Christopher Amirian
Colaborador

Idiomas: Inglés (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:

enlace oculto

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
Colaborador

Idiomas: Inglés (English )

Hi there,

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

enlace oculto

You can login here:

enlace oculto

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.