Adding interactive "add to cart" buttons to custom accessories on product page

1 0 0

Good day everyone.

I am working with the Dawn theme. While making some customizations I have added the rendering of "accessories" (products marked as relevant in a new metafield on the relevant product settings page). This is similar to the relevant or recommended products fields that were already present.


My goal is to have an small "add to cart" button beneath every "accessory" thumbnail image, which can add said product to the cart without leaving the product page. So far, I managed to send the relevant ID to the add-to-cart functionality which adds the accessory product to the cart correctly, but the page is then redirected to the shopping cart page (which throws a 302 redirect response).


I tried some Googling and looking through this forum, but I came up blank. Can anyone push me in the right direction as to how I can add a product without redirecting to the shopping cart? Maybe some Ajax code to make adding the product a background process? Although I have very little Ajax experience.


Thanks in advance for any tips or advise!

Replies 0 (0)