-
Notifications
You must be signed in to change notification settings - Fork 207
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
Fix fatal error in purchasing a subscription with PRB and ECE when the subscription's price or sign-up fee is a string #3617
Conversation
@@ -366,16 +366,16 @@ public function get_button_label() { | |||
* @since 5.2.0 | |||
* | |||
* @param object $product WC_Product_* object. | |||
* @return integer Total price. | |||
* @return float Total price. | |||
*/ | |||
public function get_product_price( $product ) { | |||
$product_price = $product->get_price(); |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
$product_price = $product->get_price(); | |
$product_price = (float) $product->get_price(); |
} | ||
|
||
return $product_price; | ||
return (float) $product_price; |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
return (float) $product_price; | |
return $product_price; |
*/ | ||
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 = $product->get_price() + WC_Subscriptions_Product::get_sign_up_fee( $product ); | ||
$product_price = (float) $product_price + (float) WC_Subscriptions_Product::get_sign_up_fee( $product ); |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
$product_price = (float) $product_price + (float) WC_Subscriptions_Product::get_sign_up_fee( $product ); | |
$product_price += (float) WC_Subscriptions_Product::get_sign_up_fee( $product ); |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Nice one, Mayisha. Works as intended!
I left some optional suggestions (which I believe makes the code easier to read).
Fixes #2966
In
get_product_price
function for PRB/ECE we need$product->get_price()
,wc_get_price_including_tax
,wc_get_price_excluding_tax
,WC_Subscriptions_Product::get_sign_up_fee
for different scenarios. These functions may return the result in different types as per the corresponding function definitionsint
/float
/string
.When the types are different the following code causes a fatal error-
Changes proposed in this Pull Request:
float
to avoid the fatal error.Testing instructions