mirror of
https://github.com/woocommerce/woocommerce-paypal-payments.git
synced 2025-09-06 17:51:41 +08:00
Add subscriptions to single product page (WIP)
This commit is contained in:
parent
1ed8f23efd
commit
e0228dbad3
1 changed files with 24 additions and 2 deletions
|
@ -36,8 +36,30 @@ class SingleProductActionHandler {
|
||||||
})
|
})
|
||||||
}).then((res)=>{
|
}).then((res)=>{
|
||||||
return res.json();
|
return res.json();
|
||||||
}).then((data) => {
|
}).then(() => {
|
||||||
location.href = this.config.redirect;
|
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;
|
||||||
|
})
|
||||||
});
|
});
|
||||||
},
|
},
|
||||||
onError: (err) => {
|
onError: (err) => {
|
||||||
|
|
Loading…
Add table
Add a link
Reference in a new issue