mirror of
https://github.com/woocommerce/woocommerce-paypal-payments.git
synced 2025-09-05 08:59:14 +08:00
Change method to add an event listener on single product page.
Add check for price not found in DOM for single product page.
This commit is contained in:
parent
0672ca4950
commit
5d43dfeb8b
1 changed files with 13 additions and 3 deletions
|
@ -51,7 +51,7 @@ class SingleProductBootstap {
|
|||
return;
|
||||
}
|
||||
|
||||
form.addEventListener('change', () => {
|
||||
jQuery(document).on('change', this.formSelector, () => {
|
||||
this.handleChange();
|
||||
|
||||
setTimeout(() => { // Wait for the DOM to be fully updated
|
||||
|
@ -91,7 +91,7 @@ class SingleProductBootstap {
|
|||
&& ((null === addToCartButton) || !addToCartButton.classList.contains('disabled'));
|
||||
}
|
||||
|
||||
priceAmount() {
|
||||
priceAmount(returnOnUndefined = 0) {
|
||||
const priceText = [
|
||||
() => document.querySelector('form.cart ins .woocommerce-Price-amount')?.innerText,
|
||||
() => document.querySelector('form.cart .woocommerce-Price-amount')?.innerText,
|
||||
|
@ -110,6 +110,10 @@ class SingleProductBootstap {
|
|||
},
|
||||
].map(f => f()).find(val => val);
|
||||
|
||||
if (typeof priceText === 'undefined') {
|
||||
return returnOnUndefined;
|
||||
}
|
||||
|
||||
if (!priceText) {
|
||||
return 0;
|
||||
}
|
||||
|
@ -118,7 +122,13 @@ class SingleProductBootstap {
|
|||
}
|
||||
|
||||
priceAmountIsZero() {
|
||||
const price = this.priceAmount();
|
||||
const price = this.priceAmount(-1);
|
||||
|
||||
// if we can't find the price in the DOM we want to return true so the button is visible.
|
||||
if (price === -1) {
|
||||
return false;
|
||||
}
|
||||
|
||||
return !price || price === 0;
|
||||
}
|
||||
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue