get_shipping_packages() public méthode

This lets us calculate costs for carts that are shipped to multiple locations. Shipping methods are responsible for looping through these packages. By default we pass the cart itself as a package - plugins can change this. through the filter and break it up.
Since: 1.5.4
public get_shipping_packages ( ) : array
Résultat array of cart items
 /**
  * Stores shipping info on the subscription
  *
  * @param WC_Subscription $subscription instance of a subscriptions object
  * @param WC_Cart $cart A cart with recurring items in it
  */
 public static function add_shipping($subscription, $cart)
 {
     // We need to make sure we only get recurring shipping packages
     WC_Subscriptions_Cart::set_calculation_type('recurring_total');
     foreach ($cart->get_shipping_packages() as $package_index => $base_package) {
         $package = WC_Subscriptions_Cart::get_calculated_shipping_for_package($base_package);
         $recurring_shipping_package_key = WC_Subscriptions_Cart::get_recurring_shipping_package_key($cart->recurring_cart_key, $package_index);
         $shipping_method_id = isset(WC()->checkout()->shipping_methods[$package_index]) ? WC()->checkout()->shipping_methods[$package_index] : '';
         if (isset(WC()->checkout()->shipping_methods[$recurring_shipping_package_key])) {
             $shipping_method_id = WC()->checkout()->shipping_methods[$recurring_shipping_package_key];
             $package_key = $recurring_shipping_package_key;
         } else {
             $package_key = $package_index;
         }
         if (isset($package['rates'][$shipping_method_id])) {
             $item_id = $subscription->add_shipping($package['rates'][$shipping_method_id]);
             if (!$item_id) {
                 throw new Exception(__('Error: Unable to create subscription. Please try again.', 'woocommerce-subscriptions'));
             }
             // Allows plugins to add order item meta to shipping
             do_action('woocommerce_add_shipping_order_item', $subscription->id, $item_id, $package_key);
             do_action('woocommerce_subscriptions_add_recurring_shipping_order_item', $subscription->id, $item_id, $package_key);
         }
     }
     WC_Subscriptions_Cart::set_calculation_type('none');
 }
 /**
  * Stores shipping info on the subscription
  *
  * @param WC_Subscription $subscription instance of a subscriptions object
  * @param WC_Cart $cart A cart with recurring items in it
  */
 public static function add_shipping($subscription, $cart)
 {
     foreach ($cart->get_shipping_packages() as $base_package) {
         $package = WC()->shipping->calculate_shipping_for_package($base_package);
         foreach (WC()->shipping->get_packages() as $package_key => $package_to_ignore) {
             if (isset($package['rates'][WC()->checkout()->shipping_methods[$package_key]])) {
                 $item_id = $subscription->add_shipping($package['rates'][WC()->checkout()->shipping_methods[$package_key]]);
                 if (!$item_id) {
                     throw new Exception(__('Error: Unable to create subscription. Please try again.', 'woocommerce-subscriptions'));
                 }
                 // Allows plugins to add order item meta to shipping
                 do_action('woocommerce_add_shipping_order_item', $subscription->id, $item_id, $package_key);
                 do_action('woocommerce_subscriptions_add_recurring_shipping_order_item', $subscription->id, $item_id, $package_key);
             }
         }
     }
 }