Add subscriptions to single product page (WIP)

This commit is contained in:
Emili Castells Guasch 2023-03-29 16:34:30 +02:00
parent 1ed8f23efd
commit e0228dbad3

View file

@ -36,8 +36,30 @@ class SingleProductActionHandler {
}) })
}).then((res)=>{ }).then((res)=>{
return res.json(); return res.json();
}).then((data) => { }).then(() => {
const id = document.querySelector('[name="add-to-cart"]').value;
const products = [new Product(id, 1, null)];
fetch(this.config.ajax.change_cart.endpoint, {
method: 'POST',
headers: {
'Content-Type': 'application/json'
},
credentials: 'same-origin',
body: JSON.stringify({
nonce: this.config.ajax.change_cart.nonce,
products,
})
}).then((result) => {
return result.json();
}).then((result) => {
if (!result.success) {
console.log(result)
throw Error(result.data.message);
}
location.href = this.config.redirect; location.href = this.config.redirect;
})
}); });
}, },
onError: (err) => { onError: (err) => {