Skip to main content

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

More
14 years 11 months ago #26807 by Rickhavoc
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.

More
14 years 11 months ago #26821 by nicolas
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.

More
14 years 11 months ago - 14 years 11 months ago #26846 by Rickhavoc
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: 14 years 11 months ago by Rickhavoc.

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

More
14 years 11 months ago #26847 by nicolas
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.

More
14 years 11 months ago #27055 by Rickhavoc
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.

More
14 years 11 months ago #27062 by nicolas
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.246 seconds
Powered by Kunena Forum