PHP 8 Compatibility – Outright crash
-
Hello,
There is a fatal error in PPOM that causes an outright crash of the script and shows an error on the frontend under PHP 8. I can’t believe that this hasn’t been found, reported, or fixed already, but here it is.
PHP Fatal error: Uncaught TypeError: Unsupported operand types: int + string in /woocommerce-product-addon/inc/prices.php:46
The issue is that under PHP 8, you can longer use + with mixed data types, so some casts are needed.
There are two ways to fix this.
Method 1:
Update the following lines to solve this crash:Line 31: $total_addon_price = floatval(ppom_price_get_addon_total( $ppom_field_prices ));
Line 32: $total_cart_fee_price = floatval(ppom_price_get_cart_fee_total( $ppom_field_prices ));
Line 39: $product_base_price = floatval($price_info[‘price’]);
Method 2:
Just update the line where the addition occurs:Line 46: $ppom_total_price = (floatval)$total_addon_price + (floatval)$product_base_price – $ppom_discount;
There may be other ways as well, but these were the two most obvious ways that I came up with and I have tested both of them on my site.
I hope that this is helpful and I look forward to a PHP 8-compatible version release soon.
Thank you!
Kevin Hock
- The topic ‘PHP 8 Compatibility – Outright crash’ is closed to new replies.