mirror of
https://github.com/woocommerce/woocommerce-paypal-payments.git
synced 2025-09-06 14:57:26 +08:00
Check the price amount with JS to fix variable products
This commit is contained in:
parent
6de1aa2ae8
commit
33ad9f6d91
2 changed files with 37 additions and 24 deletions
|
@ -9,21 +9,51 @@ class SingleProductBootstap {
|
|||
this.messages = messages;
|
||||
}
|
||||
|
||||
init() {
|
||||
|
||||
handleChange() {
|
||||
if (!this.shouldRender()) {
|
||||
this.renderer.hideButtons(this.gateway.hosted_fields.wrapper);
|
||||
this.renderer.hideButtons(this.gateway.hosted_fields.wrapper);
|
||||
this.renderer.hideButtons(this.gateway.button.wrapper);
|
||||
return;
|
||||
}
|
||||
|
||||
this.render();
|
||||
}
|
||||
|
||||
shouldRender() {
|
||||
if (document.querySelector('form.cart') === null) {
|
||||
return false;
|
||||
init() {
|
||||
|
||||
document.querySelector('form.cart').addEventListener('change', this.handleChange.bind(this))
|
||||
|
||||
if (!this.shouldRender()) {
|
||||
this.renderer.hideButtons(this.gateway.hosted_fields.wrapper);
|
||||
return;
|
||||
}
|
||||
|
||||
return true;
|
||||
this.render();
|
||||
|
||||
}
|
||||
|
||||
shouldRender() {
|
||||
|
||||
return document.querySelector('form.cart') !== null && !this.priceAmountIsZero();
|
||||
|
||||
}
|
||||
|
||||
priceAmountIsZero() {
|
||||
|
||||
let priceText = "0";
|
||||
if (document.querySelector('form.cart ins .woocommerce-Price-amount')) {
|
||||
priceText = document.querySelector('form.cart ins .woocommerce-Price-amount').innerText;
|
||||
}
|
||||
else if (document.querySelector('form.cart .woocommerce-Price-amount')) {
|
||||
priceText = document.querySelector('form.cart .woocommerce-Price-amount').innerText;
|
||||
}
|
||||
else if (document.querySelector('.woocommerce-Price-amount')) {
|
||||
priceText = document.querySelector('.woocommerce-Price-amount').innerText;
|
||||
}
|
||||
const amount = parseFloat(priceText.replace(/([^\d,\.\s]*)/g, ''));
|
||||
return amount === 0;
|
||||
|
||||
}
|
||||
|
||||
render() {
|
||||
|
@ -62,4 +92,4 @@ class SingleProductBootstap {
|
|||
}
|
||||
}
|
||||
|
||||
export default SingleProductBootstap;
|
||||
export default SingleProductBootstap;
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue