mirror of
https://github.com/woocommerce/woocommerce-paypal-payments.git
synced 2025-09-05 08:59:14 +08:00
Make PayPal Subscription products unique in cart
This commit is contained in:
parent
2aeeb78a16
commit
9b3febfdeb
1 changed files with 26 additions and 0 deletions
|
@ -80,6 +80,8 @@ class PayPalSubscriptionsModule implements ModuleInterface {
|
|||
return;
|
||||
}
|
||||
|
||||
$foo = $product;
|
||||
|
||||
$subscriptions_api_handler = $c->get( 'paypal-subscriptions.api-handler' );
|
||||
assert( $subscriptions_api_handler instanceof SubscriptionsApiHandler );
|
||||
$this->update_subscription_product_meta( $product, $subscriptions_api_handler );
|
||||
|
@ -87,6 +89,30 @@ class PayPalSubscriptionsModule implements ModuleInterface {
|
|||
12
|
||||
);
|
||||
|
||||
add_filter( 'woocommerce_add_to_cart_validation', function
|
||||
(
|
||||
$passed_validation,
|
||||
$product_id
|
||||
) {
|
||||
if ( WC()->cart->is_empty() ) {
|
||||
return $passed_validation;
|
||||
}
|
||||
|
||||
foreach ( WC()->cart->get_cart() as $cart_item_key => $cart_item ) {
|
||||
if ( get_post_meta( $cart_item['product_id'], 'ppcp_subscription_product', true ) ) {
|
||||
wc_add_notice(__('You can only have one subscription product in your cart.', 'woocommerce-paypal-payments'), 'error');
|
||||
return false;
|
||||
}
|
||||
|
||||
if ( get_post_meta( $product_id, 'ppcp_subscription_product', true ) ) {
|
||||
wc_add_notice(__('You cannot add a subscription product to a cart with other items.', 'woocommerce-paypal-payments'), 'error');
|
||||
return false;
|
||||
}
|
||||
}
|
||||
|
||||
return $passed_validation;
|
||||
}, 10, 2);
|
||||
|
||||
add_action(
|
||||
'woocommerce_save_product_variation',
|
||||
/**
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue