Skip to content

Commit c03c136

Browse files
authored
Fix fatal error in purchasing a subscription with PRB and ECE when the subscription's price or sign-up fee is a string (#3617)
* cast product price to float * add changelog * update return type * always return float
1 parent 28a5c49 commit c03c136

File tree

4 files changed

+8
-6
lines changed

4 files changed

+8
-6
lines changed

changelog.txt

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -9,6 +9,7 @@
99
* Tweak - Include page URL information in the SSL-required log for the Stripe Express Checkout Element.
1010
* Fix - Fix ECE modal not loading on pay for order page when coupon is applied.
1111
* Fix - Do not load express payment buttons on switch subscription page.
12+
* Fix - Resolve a fatal error by casting product price and subscription sign up fee to 'float' while adding them.
1213
* Fix - Return 'is_live' as true in account summary response when test mode is disabled in gateway settings and charge is enabled in Stripe account.
1314
* Fix - Prevents notices being displayed on WordPress 6.7 due to loading translations too early (only shown on stores with WP_DEBUG enabled).
1415
* Tweak - Update links to plugin documentation and Stripe documentation.

includes/payment-methods/class-wc-stripe-express-checkout-helper.php

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -147,7 +147,7 @@ public function get_total_label() {
147147
* @param bool|null $is_deposit Whether this is a deposit.
148148
* @param int $deposit_plan_id Deposit plan ID.
149149
*
150-
* @return integer Total price.
150+
* @return float Total price.
151151
*/
152152
public function get_product_price( $product, $is_deposit = null, $deposit_plan_id = 0 ) {
153153
// If prices should include tax, using tax inclusive price.
@@ -180,10 +180,10 @@ public function get_product_price( $product, $is_deposit = null, $deposit_plan_i
180180

181181
// Add subscription sign-up fees to product price.
182182
if ( in_array( $product->get_type(), [ 'subscription', 'subscription_variation' ] ) && class_exists( 'WC_Subscriptions_Product' ) ) {
183-
$product_price = $product_price + WC_Subscriptions_Product::get_sign_up_fee( $product );
183+
$product_price = (float) $product_price + (float) WC_Subscriptions_Product::get_sign_up_fee( $product );
184184
}
185185

186-
return $product_price;
186+
return (float) $product_price;
187187
}
188188

189189
/**

includes/payment-methods/class-wc-stripe-payment-request.php

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -366,13 +366,13 @@ public function get_button_label() {
366366
* @since 5.2.0
367367
*
368368
* @param object $product WC_Product_* object.
369-
* @return integer Total price.
369+
* @return float Total price.
370370
*/
371371
public function get_product_price( $product ) {
372-
$product_price = $product->get_price();
372+
$product_price = (float) $product->get_price();
373373
// Add subscription sign-up fees to product price.
374374
if ( in_array( $product->get_type(), [ 'subscription', 'subscription_variation' ] ) && class_exists( 'WC_Subscriptions_Product' ) ) {
375-
$product_price = $product->get_price() + WC_Subscriptions_Product::get_sign_up_fee( $product );
375+
$product_price += (float) WC_Subscriptions_Product::get_sign_up_fee( $product );
376376
}
377377

378378
return $product_price;

readme.txt

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -119,6 +119,7 @@ If you get stuck, you can ask for help in the [Plugin Forum](https://wordpress.o
119119
* Tweak - Include page URL information in the SSL-required log for the Stripe Express Checkout Element.
120120
* Fix - Fix ECE modal not loading on pay for order page when coupon is applied.
121121
* Fix - Do not load express payment buttons on switch subscription page.
122+
* Fix - Resolve a fatal error by casting product price and subscription sign up fee to 'float' while adding them.
122123
* Fix - Return 'is_live' as true in account summary response when test mode is disabled in gateway settings and charge is enabled in Stripe account.
123124
* Fix - Prevents notices being displayed on WordPress 6.7 due to loading translations too early (only shown on stores with WP_DEBUG enabled).
124125
* Tweak - Update links to plugin documentation and Stripe documentation.

0 commit comments

Comments
 (0)