Article Category

Returns cart contents without cart item key as parent array

Code snippet is included.

This is a Developer level doc. We are unable to provide support for customizations under our  Support Policy. See guide on adding PHP code without editing files.

API Version: 1

<?php
/**
 * Returns the cart contents without the cart item key as the parent array.
 *
 * @param  array $cart_contents Before cart contents changed.
 * @return array $cart_contents After cart contents changed.
 */
function remove_parent_cart_item_key( $cart_contents ) {
	$new_cart_contents = array();
	foreach ( $cart_contents as $item_key => $cart_item ) {
		$new_cart_contents[] = $cart_item;
	}
	return $new_cart_contents;
}
add_filter( 'cocart_return_cart_contents', 'remove_parent_cart_item_key', 0 );

Was this helpful to you?