/** * 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); }
/** * 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); }