Clearing cart when only "Free" items left in cart?

  • Posts: 156
  • Thank you received: 0
13 years 1 month ago #26807

I would like to automatically clear the cart if everything in the cart is free. How can this be done? does the hikashop have a clear function?

Please Log in or Create an account to join the conversation.

  • Posts: 82868
  • Thank you received: 13378
  • MODERATOR
13 years 1 month ago #26821

You can use such php code to clear the cart:
$class = hikashop_get('class.cart');
if($class->hasCart()){
$class->delete($class->cart->cart_id);
}

Please Log in or Create an account to join the conversation.

  • Posts: 156
  • Thank you received: 0
13 years 1 month ago #26846

this code as is is activated when the cart only has Free items in it? as in i deleted everything else and only items that are free are left. they are not being displayed in the cart but the cart still comes up with the final total of 0.0. we are hiding the items but they are still in the cart.

Last edit: 13 years 1 month ago by Rickhavoc.

Please Log in or Create an account to join the conversation.

  • Posts: 82868
  • Thank you received: 13378
  • MODERATOR
13 years 1 month ago #26847

No. It cleans the cart all the time.
You need to loop on the products in the cart to see whether the products are free or not before using it.

Please Log in or Create an account to join the conversation.

  • Posts: 156
  • Thank you received: 0
13 years 1 month ago #27055

how would i loop them through the items in the cart? got example where all i would to do is call the function to be called?

Please Log in or Create an account to join the conversation.

  • Posts: 82868
  • Thank you received: 13378
  • MODERATOR
13 years 1 month ago #27062

It's really not complicated... Here is an example:

$free = true;
foreach($this->rows as $i => $row){
if(!empty($row->prices)) $free = false;
}

if($free){
//do something
}

Please Log in or Create an account to join the conversation.

Time to create page: 0.066 seconds
Powered by Kunena Forum