woocommerce_cart_shipping_packages

Get packages to calculate shipping for.

Description

(array) apply_filters( 'woocommerce_cart_shipping_packages', (array) $array ); 

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.

Returns (array)

of cart items

Parameters (1)

0. $array — Optional. (array) => array( array( 'contents' => $this->get_items_needing_shipping(), 'contents_cost' => array_sum( wp_list_pluck( $this->get_items_needing_shipping(), 'line_total' ) ), 'applied_coupons' => $this->applied_coupons, 'user' => array( 'ID' => get_current_user_id(), ), 'destination' => array( 'country' => WC()->customer->get_shipping_country(), 'state' => WC()->customer->get_shipping_state(), 'postcode' => WC()->customer->get_shipping_postcode(), 'city' => WC()->customer->get_shipping_city(), 'address' => WC()->customer->get_shipping_address(), 'address_2' => WC()->customer->get_shipping_address_2(), ), ), )
The array.

Usage

To run the hook, copy the example below.
  1. $array = apply_filters( 'woocommerce_cart_shipping_packages', $array ); 
  2.  
  3. if ( !empty( $array ) ) { 
  4.  
  5. // everything has led up to this point... 
  6.  
  7.  
The following example is for adding a hook callback.
  1. // define the woocommerce_cart_shipping_packages callback 
  2. function filter_woocommerce_cart_shipping_packages( $array ) { 
  3. // make filter magic happen here... 
  4. return $array
  5. }; 
  6.  
  7. // add the filter 
  8. add_filter( 'woocommerce_cart_shipping_packages', 'filter_woocommerce_cart_shipping_packages', 10, 1 ); 
To remove a hook callback, use the example below.
  1. // remove the filter 
  2. remove_filter( 'woocommerce_cart_shipping_packages', 'filter_woocommerce_cart_shipping_packages', 10, 1 ); 

Defined (1)

The filter is defined in the following location(s).

/includes/class-wc-cart.php  
  1. return apply_filters( 'woocommerce_cart_shipping_packages',