/** * Removes one product from the cart */ function remove_product_from_cart($product_id) { $cart_items = get_cart_items(); foreach ($cart_items as $cart_id => $cart_item) { if ($product_id == $cart_item['product_id']) { unset($cart_items[$cart_id]); } } $_SESSION['cart_items'] = $cart_items; }
<? $cart_items = get_cart_items(); ?> <? if(!empty($cart_items)): ?> <table cellpadding="0" cellspacing="0"> <thead> <tr> <th width="320">Name of the product</th> <th width="320">Details</th> <th width="80">QTY</th> <th width="70">Single price</th> <th width="45">Remove</th> </tr> </thead> <tbody> <? foreach($cart_items as $item): ?> <tr id="cart_item_row_<? print $item['id'] ?>"> <td class="name_of_product"><? print $item['item_name'] ?></td> <td> <? if(!empty($item['custom_fields'])) : ?> <? foreach( $item['custom_fields'] as $cf): ?> <? print ($cf['custom_field_name']); ?>: <? print ($cf['custom_field_value']); ?> <br /> <? endforeach; ?> <? endif;?></td>