1

On my product page I have the default button that "Adds to cart" which adds a line item to the cart and take you to the cart page.

How do I create a second button alongside the default that adds the line item to the cart BUT then redirects the customer to the same page to select and customise another line item to add to cart?

Note: Ill very likely change the styling and text on the button (just in case anyone is concerned about usability) ;)

Add to cart

1 Answer 1

1

You would need to use javascript to change the redirect input's value

<input type="hidden" name="redirect" value="commerce/cart">

For example on the 'add and create new item' button you could do something like this using jQuery:

   $('.addAndCreateNewBtn').click(function(e){
       e.preventDefault();
       var $form = $(this).closest('form');
       $form.find("input[name='redirect']").val('anotherUrl');
       $form.submit();
   });

The above is untested, but should replace the redirect value then submit the form.

3
  • This redirects to the same page but it doesn't add an item to the cart.
    – Dan Lee
    Jun 23, 2016 at 8:37
  • is there another error on the page? Jun 27, 2016 at 7:10
  • No - I have decided to to go this route. as there needs to be some kind of feedback to the customer that the item has been placed into the cart.
    – Dan Lee
    Jun 27, 2016 at 9:00

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge that you have read and understand our privacy policy and code of conduct.

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