Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

woocommerce how to get $cart_item_key for a single product

I'm implementing a Remove Item button next to the add to cart button however I have a problem getting the variable $cart_item_key for a single product. I have the global variables $woocommerce and $product but the only way $cart_item_key is used is a foreach which doesn't help me at all as I need my code to be added in add-to-cart.php.

like image 306
Sarah McLachlane Avatar asked Nov 22 '13 08:11

Sarah McLachlane


1 Answers

You have to set the remove link for each product within loop like this,

foreach ( $woocommerce->cart->get_cart() as $cart_item_key => $cart_item ) {

 echo $cart_item_key;
 if($cart_item['product_id'] == $your_product_id_to_remove ){
    //remove single product
 }
} 

In any situation you have cart item listing; from that you have to remove, so foreach will work with your requirement.

Hope its helps..

like image 190
Jobin Avatar answered Oct 04 '22 07:10

Jobin