Add to cart
To support add to cart:
- Add an add-to-cart button in Plugin Studio.
- Use the event hooks to add the product to your Shopify cart:
window['twn-starter-config'].on = {
// ...,
'twn.add-to-cart': function (event) {
var formData = {
'items': [{
'id': event.data.itemno,
'quantity': 1
}]
};
fetch(location.protocol + '//' + location.host + '/cart/add.js', {
method: 'POST',
headers: { 'Content-Type': 'application/json' },
body: JSON.stringify(formData)
})
.then(response => { return response.json(); })
.then(response => {
location.href = '/cart'
return response;
})
}
};
Note: this example redirects to the cart after succesfully adding the product
Add to wishlist
If your shop has a wishlist app, which has an API or JS SDK, this can be supported in Tweakwise JS:
- Add a wishlist button in Plugin Studio.
- Use the event hooks to add the product to your Shopify wishlist app:
window['twn-starter-config'].on = {
// ...,
'twn.add-to-favorites': function (event) {
var productId = event.data.itemno;
// actually call your wishlist app's sdk using productId
}
};