2

I've got a site where I'd like each order to contain just one product/item. Therefore, I want to bypass the step of adding an item to a cart, and being able to keep adding items to the cart (the reason I want to skip this is because I don't want the user to end up with more than one item in the cart when they go to the checkout).

I just want to take the user straight from a 'Buy Now' button to the checkout page, where they enter their payment details and complete the order. How would I go about doing this with CartThrob?

My usual workflow would be to use the Add to Cart form, then from there, go to the checkout page. I'm a bit unsure on how to cut out this 'Add to Cart' step in the middle though - I've tried using the checkout form with my 'Buy now' button, but I just get a message saying my cart is empty so I'm obviously going about this the wrong way.

4

You can control what template a person gets sent to when they click on a button in the add_to_cart_form and you can also control what's on that template.

The default templates that Cartthrob comes with are set up to have an update_cart_form, but you don't have to put that in there. Just include a form where you take the person's details inside a checkout_form tag.

You've said you want to skip the add_to_cart_form but have also said you want to go from the Buy Now button to checkout. The Buy Now button would be in your add_to_cart_form so not sure why you think you need to skip that stage.

| improve this answer | |
  • The problem I'm finding with the add_to_cart form is that if a user changes their mind on purchasing something after clicking the 'Buy Now' button, then comes back a few seconds later and repeats the process, they'll end up with two items in their basket (either two different items if they did this to different products, or the same item twice). I want to enforce just a single item to be in their 'basket' for each checkout/order. Do you know if and how I can do this? I figured that I'd need to skip using the add_to_cart tag to get around this. – Stephen Dec 12 '12 at 13:50
  • 3
    I've done this before by writing a simple extension that uses the cartthrob_add_to_cart_start hook. All it does in that hook is call $this->EE->cartthob->cart->clear();, so every time you add something to the cart, it's cleared first. – Derek Hogue Dec 12 '12 at 14:49
  • 1
    Based on your suggestion Derek, I've just added the {exp:cartthrob:clear_cart} tag to the page that contains the Add to Cart button. This means that the cart will always be clear when they add an item to it, so I'm avoiding the original issue of having multiple items in the cart now. Thanks. – Stephen Dec 13 '12 at 5:30
0

This worked great for me:
{exp:cartthrob:clear_cart}

I just included it in the Add To Cart {embed} template, and that makes sure the cart is always empty before adding anything to it.

| improve this answer | |

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.