mirror of
https://github.com/woocommerce/woocommerce-paypal-payments.git
synced 2025-09-04 08:47:23 +08:00
Merge pull request #1731 from woocommerce/fix/wc-subscriptions-product-not-found
Fatal error when saving product while WooCommerce Subscriptions plugin is not active (2079)
This commit is contained in:
commit
effe365e39
2 changed files with 28 additions and 3 deletions
|
@ -13,6 +13,7 @@ namespace WooCommerce\PayPalCommerce\Subscription\Helper;
|
|||
|
||||
use WC_Product;
|
||||
use WC_Product_Subscription_Variation;
|
||||
use WC_Subscriptions;
|
||||
use WC_Subscriptions_Product;
|
||||
use WooCommerce\PayPalCommerce\WcGateway\Settings\Settings;
|
||||
use WooCommerce\PayPalCommerce\WcGateway\Exception\NotFoundException;
|
||||
|
@ -120,7 +121,7 @@ class SubscriptionHelper {
|
|||
*/
|
||||
public function plugin_is_active(): bool {
|
||||
|
||||
return class_exists( \WC_Subscriptions::class );
|
||||
return class_exists( WC_Subscriptions::class ) && class_exists( WC_Subscriptions_Product::class );
|
||||
}
|
||||
|
||||
/**
|
||||
|
|
|
@ -194,7 +194,18 @@ class SubscriptionModule implements ModuleInterface {
|
|||
//phpcs:disable WordPress.Security.NonceVerification.Recommended
|
||||
$post_id = wc_clean( wp_unslash( $_GET['post'] ?? '' ) );
|
||||
$product = wc_get_product( $post_id );
|
||||
if ( ! ( is_a( $product, WC_Product::class ) || is_a( $product, WC_Product_Subscription_Variation::class ) ) || ! WC_Subscriptions_Product::is_subscription( $product ) ) {
|
||||
if ( ! ( is_a( $product, WC_Product::class ) ) ) {
|
||||
return;
|
||||
}
|
||||
|
||||
$subscriptions_helper = $c->get( 'subscription.helper' );
|
||||
assert( $subscriptions_helper instanceof SubscriptionHelper );
|
||||
|
||||
if (
|
||||
! $subscriptions_helper->plugin_is_active()
|
||||
|| ! is_a( $product, WC_Product_Subscription_Variation::class )
|
||||
|| ! WC_Subscriptions_Product::is_subscription( $product )
|
||||
) {
|
||||
return;
|
||||
}
|
||||
|
||||
|
@ -210,6 +221,14 @@ class SubscriptionModule implements ModuleInterface {
|
|||
$products = array( $this->set_product_config( $product ) );
|
||||
if ( $product->get_type() === 'variable-subscription' ) {
|
||||
$products = array();
|
||||
|
||||
/**
|
||||
* Suppress pslam.
|
||||
*
|
||||
* @psalm-suppress TypeDoesNotContainType
|
||||
*
|
||||
* WC_Product_Variable_Subscription extends WC_Product_Variable.
|
||||
*/
|
||||
assert( $product instanceof WC_Product_Variable );
|
||||
$available_variations = $product->get_available_variations();
|
||||
foreach ( $available_variations as $variation ) {
|
||||
|
@ -541,8 +560,13 @@ class SubscriptionModule implements ModuleInterface {
|
|||
*/
|
||||
function( $variation_id ) use ( $c ) {
|
||||
$wcsnonce_save_variations = wc_clean( wp_unslash( $_POST['_wcsnonce_save_variations'] ?? '' ) );
|
||||
|
||||
$subscriptions_helper = $c->get( 'subscription.helper' );
|
||||
assert( $subscriptions_helper instanceof SubscriptionHelper );
|
||||
|
||||
if (
|
||||
! WC_Subscriptions_Product::is_subscription( $variation_id )
|
||||
! $subscriptions_helper->plugin_is_active()
|
||||
|| ! WC_Subscriptions_Product::is_subscription( $variation_id )
|
||||
|| ! is_string( $wcsnonce_save_variations )
|
||||
|| ! wp_verify_nonce( $wcsnonce_save_variations, 'wcs_subscription_variations' )
|
||||
) {
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue