/** * Update shipping method on the subscription if the order changed anything * * @param WC_Order $order The new order * @param WC_Subscription $subscription The original subscription * @param WC_Cart $recurring_cart A recurring cart */ public static function update_shipping_methods($subscription, $recurring_cart) { // First, archive all the shipping methods foreach ($subscription->get_shipping_methods() as $shipping_method_id => $shipping_method) { wc_update_order_item($shipping_method_id, array('order_item_type' => 'shipping_switched')); } // Then zero the order_shipping total so we have a clean slate to add to $subscription->order_shipping = 0; WC_Subscriptions_Checkout::add_shipping($subscription, $recurring_cart); // Now update subscription object order_shipping to reflect updated values so it doesn't stay 0 $subscription->order_shipping = get_post_meta($subscription->id, '_order_shipping', true); }
/** * Creates subscriptions against a users account with a status of pending when a user creates * an order containing subscriptions. * * @param int|WC_Order $order The order ID or WC_Order object to create the subscription from. * @since 1.0 */ public static function process_subscriptions_on_checkout($order) { _deprecated_function(__METHOD__, '2.0', 'WC_Subscriptions_Checkout::process_checkout()'); if (!empty($_POST['_wpnonce']) && wp_verify_nonce($_POST['_wpnonce'], 'woocommerce-process_checkout')) { WC_Subscriptions_Checkout::process_checkout($order, $_POST); } }
/** * If shopping cart contains subscriptions, make sure a user can register on the checkout page * * @since 1.0 */ public static function make_checkout_registration_possible($checkout = '') { if (WC_Subscriptions_Cart::cart_contains_subscription() && !is_user_logged_in()) { // Make sure users can sign up if (false === $checkout->enable_signup) { $checkout->enable_signup = true; self::$signup_option_changed = true; } // Make sure users are required to register an account if (true === $checkout->enable_guest_checkout) { $checkout->enable_guest_checkout = false; self::$guest_checkout_option_changed = true; if (!is_user_logged_in()) { $checkout->must_create_account = true; } } } }
/** * If shopping cart contains subscriptions, make sure a user can register on the checkout page * * @since 1.0 */ public static function make_checkout_registration_possible() { if (WC_Subscriptions_Cart::cart_contains_subscription() && !is_user_logged_in()) { // Make sure users can sign up if ('no' == get_option('woocommerce_enable_signup_and_login_from_checkout')) { update_option('woocommerce_enable_signup_and_login_from_checkout', 'yes'); self::$signup_option_changed = true; } // Make sure users are required to register an account if ('yes' == get_option('woocommerce_enable_guest_checkout')) { update_option('woocommerce_enable_guest_checkout', 'no'); self::$guest_checkout_option_changed = true; } } }
// WC Subscriptions 2.0 needs this if (class_exists('WC_Subscriptions_Cart') && WC_Subscriptions_Cart::cart_contains_subscription()) { sleep(5); $parent_order = new WC_Order(intval($_GET['sid'])); $subscriptions = array(); // First clear out any subscriptions created for a failed payment to give us a clean slate for creating new subscriptions $subscriptions = wcs_get_subscriptions_for_order($parent_order->id, array('order_type' => 'parent')); if (!empty($subscriptions)) { foreach ($subscriptions as $subscription) { wp_delete_post($subscription->id); } } WC()->cart->calculate_totals(); // Create new subscriptions for each group of subscription products in the cart (that is not a renewal) foreach (WC()->cart->recurring_carts as $recurring_cart) { $subscription = WC_Subscriptions_Checkout::create_subscription($parent_order, $recurring_cart); // Exceptions are caught by WooCommerce $subscription->payment_complete(); if (is_wp_error($subscription)) { throw new Exception($subscription->get_error_message()); } do_action('woocommerce_checkout_subscription_created', $subscription, $parent_order, $recurring_cart); } do_action('subscriptions_created_for_order', $parent_order); // Backward compatibility } echo $snippet; do_action('klarna_after_kco_confirmation', intval($_GET['sid'])); do_action('woocommerce_thankyou', intval($_GET['sid'])); // Clear session and empty cart WC()->session->__unset('klarna_checkout');
/** * If shopping cart contains subscriptions, make sure a user can register on the checkout page * * @since 1.0 */ public static function make_checkout_registration_possible($checkout = '') { if (WC_Subscriptions_Cart::cart_contains_subscription() && !is_user_logged_in()) { if (version_compare(WOOCOMMERCE_VERSION, "2.0.0") >= 0) { // WC 2.0+ // Make sure users can sign up if (false === $checkout->enable_signup) { $checkout->enable_signup = true; self::$signup_option_changed = true; } // Make sure users are required to register an account if (true === $checkout->enable_guest_checkout) { $checkout->enable_guest_checkout = false; self::$guest_checkout_option_changed = true; if (!is_user_logged_in()) { $checkout->must_create_account = true; } } } else { // WC 1.x // Make sure users can sign up if ('no' == get_option('woocommerce_enable_signup_and_login_from_checkout')) { update_option('woocommerce_enable_signup_and_login_from_checkout', 'yes'); self::$signup_option_changed = true; } // Make sure users are required to register an account if ('yes' == get_option('woocommerce_enable_guest_checkout')) { update_option('woocommerce_enable_guest_checkout', 'no'); self::$guest_checkout_option_changed = true; } } } }
/** * Update shipping method on the subscription if the order changed anything * * @param WC_Order $order The new order * @param WC_Subscription $subscription The original subscription * @param WC_Cart $recurring_cart A recurring cart */ public static function update_shipping_methods($subscription, $recurring_cart) { // First, archive all the shipping methods foreach ($subscription->get_shipping_methods() as $shipping_method_id => $shipping_method) { wc_update_order_item($shipping_method_id, array('order_item_type' => 'shipping_switched')); } WC_Subscriptions_Checkout::add_shipping($subscription, $recurring_cart); }