autoship_get_all_variation_cart_options()

(src /cart.php) The function gathers the autoship data for a product and its variations and returns the data in an array formatted with the same key names as that returned from the autoship_product_discount ajax call. This function is called when rendering the Add to Cart section for variable products and allows the autoship data to be included on page load vs having to call it via ajax.

Example

function autoship_get_all_variation_cart_options( $variable_product ){

  $product = new WC_Product_Variable( $variable_product );
  $variations = $product->get_available_variations();

  $autoship_variation_data = array();
  foreach ($variations as $variation ) {
    $new_product = wc_get_product( $variation['variation_id'] );
    $data = autoship_product_discount_data( $new_product );
    $autoship_variation_data[$variation['variation_id']] = apply_filters( 'autoship_get_all_variation_cart_options', $data, $variation['variation_id'] , $new_product );
  }

  return $autoship_variation_data;
}