3

Is there any way to limit only one item in a cart overall?

I want to give the client the ability to add one thing and one thing only to the cart, effectively disabling anything else unless they remove the item they have in cart itself?

{exp:store:cart limit='1'} seems too easy...?

2

You can do this by building a conditional using {qty_in_cart} to show the Add To Cart:

   {exp:store:product entry_id="{entry_id}"  return="/checkout"}
        {if qty_in_cart == "0"}
            <select id="item_qty" name="item_qty">
                <option value="1">1</option>
            </select>
            <input type="submit" name="submit" value="Add To Cart">
        {if:else}
            <p>Limit 1 per order</p>
        {/if}       
    {/exp:store:product}

Also, remove the ability to change quantity on the My Cart page... The user should only be able to delete the product from the cart.

| improve this answer | |
3

What Anna said, although note that the {qty_in_cart} variable only refers to the current product. If you want to prevent the custom from purchasing any other items, you could either wrap your whole product form in a conditional:

{exp:store:cart}
    {if no_items}
        // product form here
    {/if}
{/exp:store:cart}

Alternatively, you could just empty the cart every time a new product is added:

{exp:store:product entry_id="1" empty_cart="yes"}
    // add to cart button here
{/exp:store:product}
| improve this answer | |
  • I did combination of the two on this one. I locked down all of the buttons to add to cart, then when the cart was full of one thing, added a link to checkout. I will keep the empty cart = yes in mind however, I hadn't thought of that! – Aaron Nov 11 '13 at 22:01

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.