🎨 Isolate condition for preview buttons

This step makes it easier to refactor/update the logic in the next step.
This commit is contained in:
Philipp Stracker 2024-06-03 17:19:18 +02:00
parent fa76f1a73c
commit d1a93a1b55
No known key found for this signature in database
2 changed files with 23 additions and 3 deletions

View file

@ -47,6 +47,16 @@ import widgetBuilder from "../../../ppcp-button/resources/js/modules/Renderer/Wi
}, 100);
});
/**
* Decides, whether to display the Google Pay preview button.
*
* @return {boolean}
*/
const shouldDisplayPreviewButton = function() {
// TODO - original condition, which is wrong.
return jQuery('#ppcp-googlepay_button_enabled').is(':checked');
}
const applyConfigOptions = function (buttonConfig) {
buttonConfig.button = buttonConfig.button || {};
buttonConfig.button.style = buttonConfig.button.style || {};
@ -58,7 +68,7 @@ import widgetBuilder from "../../../ppcp-button/resources/js/modules/Renderer/Wi
const createButton = function (ppcpConfig) {
const selector = ppcpConfig.button.wrapper + 'GooglePay';
if (!jQuery('#ppcp-googlepay_button_enabled').is(':checked')) {
if (!shouldDisplayPreviewButton()) {
jQuery(selector).remove();
return;
}