autoship_update_cart_item_data (function)

(src/cart.php) Adds / updates Autoship Schedule Date in cart for items being added / updated. Takes $cart_item_data, $product_id, $variation_id, $quantity, and $schedule_data as parameters.


* Adds / updates the Autoship Schedule Data in the Cart Item being added / updated.


* @param array $cart_item_data cart item data we want to update.

* @param int $product_id ID of the product associated with the cart item data.

* @param int $variation_id ID of the variation associated with the cart item data.

* @param int $quantity The quantity being added


* @return array The updated cart item's data array.


function autoship_update_cart_item_data( $cart_item_data, $product_id, $variation_id, $quantity, $schedule_data ) {

// Default the Autoship Values for the supplied data

// allow devs to adjust before we run our cart operations.

$default_schedule_values = autoship_cart_item_keys( true );

$schedule_data = apply_filters( 'autoship_update_cart_item_data_schedule_values',

array_merge( $default_schedule_values, $schedule_data ),

$schedule_data, $cart_item_data, $product_id, $variation_id, $quantity );

// No valid autoship schedule so we don't continue

// however, we still update the item's data with the re-freshed data

$schedule_values = autoship_get_item_data_schedule_values( $schedule_data );

if ( !autoship_item_data_has_valid_schedule( $schedule_values ) )

return array_merge( $cart_item_data, $schedule_values );

extract( $schedule_values );

// Adjust the Relative Next Occurrence if needed

$schedule_values['autoship_next_occurrence'] = isset( $autoship_next_occurrence ) && !empty( $autoship_next_occurrence ) ? autoship_maybe_update_cart_item_relative_next_occurrence( $product_id, $autoship_next_occurrence, $autoship_frequency_type, $autoship_frequency ) : autoship_get_product_default_relative_next_occurrence( $product_id, $autoship_frequency_type, $autoship_frequency );

// Now attach the Schedule Values to the cart item

foreach ( $schedule_values as $key => $value )

$cart_item_data[$key] = $value;

return $cart_item_data;


Found in the Functions