autoship_update_cart_action (function)

(src/cart.php) Updates the Autoship Frequency and Type when cart is updated. It takes as its parameter and returns $cart_updated (boolean) whether the cart was updated or not.


/**

* Updates the Autoship Frequency and Type when cart is updated.

*

* @param bool $cart_updated True if the cart was updated.

* @return bool The adjusted cart updated flag.

*/

function autoship_update_cart_action( $cart_updated ) {

// If the cart's empty return.

if ( WC()->cart->is_empty() || ( 'no' == autoship_cart_schedule_options_enabled() ) )

return $cart_updated;

// Go through the cart items and check for Autoship Flags.

foreach ( WC()->cart->get_cart() as $cart_item_key => $values ) {

// Check for any updates to the schedule data

$schedule_data = autoship_get_item_data_schedule_values( $_POST['cart'][ $cart_item_key ] );

// Add the Schedule Data to the Cart Item Data

$updated_item_data = autoship_update_cart_item_data( $values, $values['product_id'], $values['variation_id'], $_POST['cart'][ $cart_item_key ]['qty'], $schedule_data );

// Now Re-process the cart item to refresh checkout price, etc if needed.

WC()->cart->cart_contents[ $cart_item_key ] = autoship_add_cart_item( $updated_item_data, $cart_item_key );

$cart_updated = true;

}

return $cart_updated;

}