mirror of
https://github.com/woocommerce/woocommerce-paypal-payments.git
synced 2025-09-06 10:55:00 +08:00
Fix add to cart limits of non-subscription products
This commit is contained in:
parent
36a13f6500
commit
636b905ef0
1 changed files with 13 additions and 17 deletions
|
@ -108,35 +108,31 @@ class PayPalSubscriptionsModule implements ModuleInterface {
|
||||||
}
|
}
|
||||||
|
|
||||||
$product = wc_get_product( $product_id );
|
$product = wc_get_product( $product_id );
|
||||||
|
|
||||||
$settings = $c->get( 'wcgateway.settings' );
|
$settings = $c->get( 'wcgateway.settings' );
|
||||||
assert( $settings instanceof Settings );
|
assert( $settings instanceof Settings );
|
||||||
|
|
||||||
$subscriptions_mode = $settings->has( 'subscriptions_mode' ) ? $settings->get( 'subscriptions_mode' ) : '';
|
$subscriptions_mode = $settings->has( 'subscriptions_mode' ) ? $settings->get( 'subscriptions_mode' ) : '';
|
||||||
|
$is_paypal_subscription = static function ( $product ) use ( $subscriptions_mode ): bool {
|
||||||
|
return $product &&
|
||||||
|
in_array( $product->get_type(), array( 'subscription', 'variable-subscription' ), true ) &&
|
||||||
|
'subscriptions_api' === $subscriptions_mode &&
|
||||||
|
$product->get_meta( '_ppcp_enable_subscription_product', true ) === 'yes';
|
||||||
|
};
|
||||||
|
|
||||||
if ( 'subscriptions_api' !== $subscriptions_mode ) {
|
if ( $is_paypal_subscription( $product ) ) {
|
||||||
if ( $product && $product->get_sold_individually() ) {
|
|
||||||
$product->set_sold_individually( false );
|
|
||||||
$product->save();
|
|
||||||
}
|
|
||||||
|
|
||||||
return $passed_validation;
|
|
||||||
}
|
|
||||||
|
|
||||||
if ( $product && $product->get_meta( '_ppcp_enable_subscription_product', true ) === 'yes' ) {
|
|
||||||
if ( ! $product->get_sold_individually() ) {
|
if ( ! $product->get_sold_individually() ) {
|
||||||
$product->set_sold_individually( true );
|
$product->set_sold_individually( true );
|
||||||
$product->save();
|
$product->save();
|
||||||
}
|
}
|
||||||
|
|
||||||
wc_add_notice( __( 'You cannot add a subscription product to a cart with other items.', 'woocommerce-paypal-payments' ), 'error' );
|
wc_add_notice( __( 'You cannot add a PayPal Subscription product to a cart with other items.', 'woocommerce-paypal-payments' ), 'error' );
|
||||||
return false;
|
return false;
|
||||||
}
|
}
|
||||||
|
|
||||||
foreach ( WC()->cart->get_cart() as $cart_item_key => $cart_item ) {
|
foreach ( WC()->cart->get_cart() as $cart_item ) {
|
||||||
$cart_product = wc_get_product( $cart_item['product_id'] );
|
$cart_product = wc_get_product( $cart_item['product_id'] );
|
||||||
if ( $cart_product && $cart_product->get_meta( '_ppcp_enable_subscription_product', true ) === 'yes' ) {
|
if ( $is_paypal_subscription( $cart_product ) ) {
|
||||||
wc_add_notice( __( 'You can only have one subscription product in your cart.', 'woocommerce-paypal-payments' ), 'error' );
|
wc_add_notice( __( 'You can only have one PayPal Subscription product in your cart.', 'woocommerce-paypal-payments' ), 'error' );
|
||||||
return false;
|
return false;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
Loading…
Add table
Add a link
Reference in a new issue