Skip to content

Commit

Permalink
Handle fatal errors when subscription plugin gets deactivated due to …
Browse files Browse the repository at this point in the history
…outdated version (#10416)
  • Loading branch information
zmaglica authored Feb 21, 2025
1 parent a615dd0 commit e101a39
Show file tree
Hide file tree
Showing 3 changed files with 14 additions and 3 deletions.
Original file line number Diff line number Diff line change
@@ -0,0 +1,4 @@
Significance: patch
Type: fix

Prevent fatal errors when subscription is deactivated due outdated version.
Original file line number Diff line number Diff line change
Expand Up @@ -69,6 +69,9 @@ public function is_payment_recurring( $order_id ) {
* @return bool Indicates whether the save payment method checkbox should be displayed or not.
*/
public function display_save_payment_method_checkbox( $display ) {
if ( ! class_exists( 'WC_Subscriptions_Cart' ) ) {
return false;
}
if ( WC_Subscriptions_Cart::cart_contains_subscription() || $this->is_changing_payment_method_for_subscription() ) {
return false;
}
Expand All @@ -83,7 +86,7 @@ public function display_save_payment_method_checkbox( $display ) {
* @return bool
*/
public function is_subscription_item_in_cart() {
if ( $this->is_subscriptions_enabled() ) {
if ( class_exists( 'WC_Subscriptions_Cart' ) && $this->is_subscriptions_enabled() ) {
return WC_Subscriptions_Cart::cart_contains_subscription() || $this->cart_contains_renewal();
}
return false;
Expand Down
8 changes: 6 additions & 2 deletions includes/subscriptions/class-wc-payments-product-service.php
Original file line number Diff line number Diff line change
Expand Up @@ -459,7 +459,7 @@ public function archive_price( string $wcpay_price_id, $test_mode = null ) {
* @param int $product_id ID of the product that's being saved.
*/
public function limit_subscription_product_intervals( $product_id ) {
if ( $this->is_subscriptions_plugin_active() ) {
if ( $this->is_subscriptions_plugin_active() || ! class_exists( 'WC_Subscriptions_Product' ) ) {
return;
}

Expand Down Expand Up @@ -500,7 +500,7 @@ public function limit_subscription_product_intervals( $product_id ) {
* @param int $index Variation index in the incoming array.
*/
public function limit_subscription_variation_intervals( $product_id, $index ) {
if ( $this->is_subscriptions_plugin_active() ) {
if ( $this->is_subscriptions_plugin_active() || ! class_exists( 'WC_Subscriptions_Product' ) ) {
return;
}

Expand Down Expand Up @@ -793,6 +793,10 @@ public function get_wcpay_price_id( WC_Product $product, $test_mode = null ): st
wc_deprecated_function( __FUNCTION__, '3.3.0' );
$price_id = $product->get_meta( self::get_wcpay_price_id_option( $test_mode ), true );

if ( ! class_exists( 'WC_Subscriptions_Product' ) ) {
return $price_id;
}

// If the subscription product doesn't have a WC Pay price ID, create one now.
if ( empty( $price_id ) && WC_Subscriptions_Product::is_subscription( $product ) ) {
$is_current_environment = null === $test_mode || WC_Payments::mode()->is_test() === $test_mode;
Expand Down

0 comments on commit e101a39

Please sign in to comment.