Forum

Thread tagged as: Question, Problem, Shop

Add product to cart without page refresh

Hello,

I am setting up a website for ONE specific product. I would like to be able to press a call to action button, which adds 1 product to the invisible cart, and then shows a modal with a customer registration form.

Button > 1 item in cart > Pop up modal > Fill in registration form > Buy now > Gateway

My problem is that when an item is added to the cart, the page is refreshed, so a modal toggle attribute on the submit button is not working.

What could be a possible solution?

Mike Hendriks

Mike Hendriks 0 points

  • 3 years ago

My temporary solution now is that I check if there is >= 1 item in cart. If so, when the page reloads a modal is shown. Is there an other solution?

Hussein Al Hammad

Hussein Al Hammad 105 points
Registered Developer

Hello Mike,

If you don't want the page to reload on form submission, you can post the form with Javascript to another page and programmatically add the product to cart:

perch_shop_add_to_cart(1234);

https://docs.grabaperch.com/addons/shop/examples/add-to-cart-php/