-
Notifications
You must be signed in to change notification settings - Fork 210
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Fatal error with PRBs and Subscriptions when the subscription's price or sign-up fee is a string #2966
Comments
I have encountered this error (PHP 8.0) today. Please see the Log:
PHP Version: PHP 8.0.25 (cli) (built: Oct 28 2022 18:02:51) ( NTS )
Copyright (c) The PHP Group
Zend Engine v4.0.25, Copyright (c) Zend Technologies
with Zend OPcache v8.0.25, Copyright (c), by Zend Technologies WordPress & Plugin:
Code in question: woocommerce-gateway-stripe/includes/payment-methods/class-wc-stripe-payment-request.php Lines 353 to 370 in 87c3bd0
After digging into the code it seems both Casting both output as float seems resolves the issue in my server. public function get_product_price( $product ) {
$product_price = $product->get_price();
// Add subscription sign-up fees to product price.
if ( in_array( $product->get_type(), [ 'subscription', 'subscription_variation' ] ) && class_exists( 'WC_Subscriptions_Product' ) ) {
$product_price = (float) $product->get_price() + (float) WC_Subscriptions_Product::get_sign_up_fee( $product );
}
return $product_price;
} |
8753128-zen |
The issue was in the file: ‘/wp-content/plugins/woocommerce-gateway-stripe/includes/payment-methods/class-wc-stripe-payment-request.php’ line 365, where I had to add (int) casting to both values: broken: $product_price = $product->get_price() + WC_Subscriptions_Product::get_sign_up_fee( $product ); fixed: $product_price = (int)$product->get_price() + (int)WC_Subscriptions_Product::get_sign_up_fee( $product ); |
Broken again in the latest update. |
broken: $product_price = $product->get_price() + WC_Subscriptions_Product::get_sign_up_fee( $product ); fixed: $product_price = (int)$product->get_price() + (int)WC_Subscriptions_Product::get_sign_up_fee( $product ); I had to change this on line 370 |
@SusanBradley casting to float would bet better. $product_price = (float)$product->get_price() + (float)WC_Subscriptions_Product::get_sign_up_fee( $product ); |
Describe the bug
There's a fatal error when using Payment Request Buttons, like Google Pay or Apple Pay, with subscriptions in some scenarios.
The error comes from this line.
WC_Subscriptions_Product::get_sign_up_fee() may return a string.
To Reproduce
Steps to reproduce the behavior:
TBC (I think this happens with PHP 8.1)
Expected behavior
No errors must be triggered when using PRBs with subscriptions.
Additional context
Slack thread p1709233934325419-slack-C7U3Y3VMY
The text was updated successfully, but these errors were encountered: