| @@ -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 | |
| @@ -369,9 +383,9 @@ | ||
| 369 | 383 | 'recurring_limit' => $price_data['recurring_limit'], |
| 370 | 384 | 'time' => $time, |
| 371 | 385 | 'type' => $type, |
| 372 | 386 | 'description' => $description, |
| 373 | - 'can_user_cancel' => $cart_item['data']->get_meta( '_subscrpt_user_cancel' ), | |
| 387 | + 'can_user_cancel' => Helper::can_user_cancel( $cart_item['data']->get_meta( '_subscrpt_user_cancel' ) ) ? 'yes' : 'no', | |
| 374 | 388 | 'max_no_payment' => ! empty( $cart_item['subscrpt_max_no_payment'] ) |
| 375 | 389 | ? (int) $cart_item['subscrpt_max_no_payment'] |
| 376 | 390 | : $cart_item['data']->get_meta( '_subscrpt_max_no_payment' ), |
| 377 | 391 | 'split_total' => isset( $cart_item['subscrpt_split_total'] ) ? (float) $cart_item['subscrpt_split_total'] : null, |