mirror of
https://github.com/woocommerce/woocommerce-paypal-payments.git
synced 2025-09-06 18:16:38 +08:00
✨ Add preview button eligibility check
This commit is contained in:
parent
d2f0cb1c31
commit
d1318d7247
1 changed files with 20 additions and 0 deletions
|
@ -184,6 +184,10 @@ class PreviewButtonManager {
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
if (!this.shouldInsertPreviewButton(id)) {
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
|
||||||
if (!this.buttons[id]) {
|
if (!this.buttons[id]) {
|
||||||
this._addButton(id, ppcpConfig);
|
this._addButton(id, ppcpConfig);
|
||||||
} else {
|
} else {
|
||||||
|
@ -192,6 +196,22 @@ class PreviewButtonManager {
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Determines if the preview box supports the current button.
|
||||||
|
*
|
||||||
|
* When this function returns false, this manager instance does not create a new preview button.
|
||||||
|
*
|
||||||
|
* @param {string} previewId - ID of the inner preview box container.
|
||||||
|
* @return {boolean} True if the box is eligible for the preview button, false otherwise.
|
||||||
|
*/
|
||||||
|
shouldInsertPreviewButton(previewId) {
|
||||||
|
const container = document.querySelector(previewId);
|
||||||
|
const box = container.closest('.ppcp-preview');
|
||||||
|
const limit = box.dataset.ppcpPreviewBlock ?? 'all';
|
||||||
|
|
||||||
|
return ('all' === limit) || (this.methodName === limit);
|
||||||
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Applies a new configuration to an existing preview button.
|
* Applies a new configuration to an existing preview button.
|
||||||
*/
|
*/
|
||||||
|
|
Loading…
Add table
Add a link
Reference in a new issue