| @@ -86,8 +86,22 @@ | ||
| 86 | 86 | * @param int $product_id Product Id. |
| 87 | 87 | * @return array |
| 88 | 88 | */ |
| 89 | 89 | public function validate_cart_items( $product_id ) { |
| 90 | + /** | |
| 91 | + * Filters whether the cart may hold more than one subscription, or a | |
| 92 | + * subscription alongside a normal product, bypassing the restriction below. | |
| 93 | + * | |
| 94 | + * @param bool $allow Whether to allow it. Default false. | |
| 95 | + * @param int $product_id Product being added to the cart. | |
| 96 | + */ | |
| 97 | + if ( apply_filters( 'subscrpt_allow_multiple_subscriptions_in_cart', false, $product_id ) ) { | |
| 98 | + return [ | |
| 99 | + 'failed' => false, | |
| 100 | + 'error_notice' => null, | |
| 101 | + ]; | |
| 102 | + } | |
| 103 | + | |
| 90 | 104 | $cart_items = WC()->cart->cart_contents; |
| 91 | 105 | |
| 92 | 106 | $product = Subscription::get_subs_product( $product_id ); |
| 93 | 107 | |