How to know number of items added to cart in WordPress shopping cart with SHOPP PLUGIN
I'm doing a shopping cart with wordpress using Shopp Plugin.
How can i know the number of items added开发者_JS百科 to cart here.Any code for this. Can any one please help me.
I added a code to count the number of items in cart and output them.
Hope it helps!
<p class="cartinfo">
<?php if (shopp('cart','hasitems')): ?>
<?php $total_items = 0; ?>
<?php while(shopp('cart','items')): ?>
<?php $total_items = $total_items + 1; ?>
<?php endwhile; ?>
<?php echo $total_items;?> <?php if ($total_items = 1) {echo'Item';} else {echo'Items';} ?> (<?php shopp('cart','subtotal'); ?>)
<?php else: ?>
0 Items in Cart :(
<?php endif; ?>
</p>
I think this does what you want?
<?php shopp('cart','totalitems'); ?>
Here are the docs on it: Cart_Tags#totalitems
UPDATED: The docs are now open to the public and updated. Here is a new link for the same function. Note the 'alternative forms' available: shopp('cart','total-items')
This part has always been a little confusing in Shopp.
If you need the number of unique items in the cart you should use
shopp('cart','totalitems','options...');
(for example: 5 apples, 3 pears, 2 carrots would result in 3)
If you need the number of items in the cart you should use
shopp('cart','total-quantity','options...');
(for example: 2 apples, 3 pears, 1 carrot would result in 6)
To use the value in a variable, set options to 'return=true'
精彩评论