/**
  * Add a 'new-payment-method' handler to the @see WC_Subscription::can_be_updated_to() function
  * to determine whether the recurring payment method on a subscription can be changed.
  *
  * For the recurring payment method to be changeable, the subscription must be active, have future (automatic) payments
  * and use a payment gateway which allows the subscription to be cancelled.
  *
  * @param bool $subscription_can_be_changed Flag of whether the subscription can be changed to
  * @param string $new_status_or_meta The status or meta data you want to change th subscription to. Can be 'active', 'on-hold', 'cancelled', 'expired', 'trash', 'deleted', 'failed', 'new-payment-date' or some other value attached to the 'woocommerce_can_subscription_be_changed_to' filter.
  * @param object $args Set of values used in @see WC_Subscriptions_Manager::can_subscription_be_changed_to() for determining if a subscription can be changes, include:
  *			'subscription_key'           string A subscription key of the form created by @see WC_Subscriptions_Manager::get_subscription_key()
  *			'subscription'               array Subscription of the form returned by @see WC_Subscriptions_Manager::get_subscription()
  *			'user_id'                    int The ID of the subscriber.
  *			'order'                      WC_Order The order which recorded the successful payment (to make up for the failed automatic payment).
  *			'payment_gateway'            WC_Payment_Gateway The subscription's recurring payment gateway
  *			'order_uses_manual_payments' bool A boolean flag indicating whether the subscription requires manual renewal payment.
  * @since 1.4
  */
 public static function can_subscription_be_updated_to_new_payment_method($subscription_can_be_changed, $subscription)
 {
     if (WC_Subscriptions_Payment_Gateways::one_gateway_supports('subscription_payment_method_change_customer') && $subscription->get_time('next_payment') > 0 && !$subscription->is_manual() && $subscription->payment_method_supports('subscription_cancellation') && $subscription->has_status('active')) {
         $subscription_can_be_changed = true;
     } else {
         $subscription_can_be_changed = false;
     }
     return $subscription_can_be_changed;
 }
Exemplo n.º 2
0
 /**
  * When a subscription is added to the cart, remove other products/subscriptions to
  * work with PayPal Standard, which only accept one subscription per checkout.
  *
  * If multiple purchase flag is set, allow them to be added at the same time.
  *
  * @since 1.0
  */
 public static function maybe_empty_cart($valid, $product_id, $quantity)
 {
     $is_subscription = WC_Subscriptions_Product::is_subscription($product_id);
     $cart_contains_subscription = WC_Subscriptions_Cart::cart_contains_subscription();
     $multiple_subscriptions_possible = WC_Subscriptions_Payment_Gateways::one_gateway_supports('multiple_subscriptions');
     $manual_renewals_enabled = 'yes' == get_option(WC_Subscriptions_Admin::$option_prefix . '_accept_manual_renewals', 'no') ? true : false;
     if ($is_subscription && 'yes' != get_option(WC_Subscriptions_Admin::$option_prefix . '_multiple_purchase', 'no')) {
         WC()->cart->empty_cart();
     } elseif ($is_subscription && wcs_cart_contains_renewal() && !$multiple_subscriptions_possible && !$manual_renewals_enabled) {
         self::remove_subscriptions_from_cart();
         self::add_notice(__('A subscription renewal has been removed from your cart. Multiple subscriptions can not be purchased at the same time.', 'woocommerce-subscriptions'), 'notice');
     } elseif ($is_subscription && $cart_contains_subscription && !$multiple_subscriptions_possible && !$manual_renewals_enabled) {
         self::remove_subscriptions_from_cart();
         self::add_notice(__('A subscription has been removed from your cart. Due to payment gateway restrictions, different subscription products can not be purchased at the same time.', 'woocommerce-subscriptions'), 'notice');
     } elseif ($cart_contains_subscription && 'yes' != get_option(WC_Subscriptions_Admin::$option_prefix . '_multiple_purchase', 'no')) {
         self::remove_subscriptions_from_cart();
         self::add_notice(__('A subscription has been removed from your cart. Products and subscriptions can not be purchased at the same time.', 'woocommerce-subscriptions'), 'notice');
         // Redirect to cart page to remove subscription & notify shopper
         add_filter('add_to_cart_fragments', __CLASS__ . '::redirect_ajax_add_to_cart');
     }
     return $valid;
 }