From 89288603c37b76d0e206bb917c156dcada52f4a0 Mon Sep 17 00:00:00 2001
From: Pedro Silva
Date: Wed, 9 Aug 2023 15:03:54 +0100
Subject: [PATCH] Fix in the Single Product load SingleProductBootstap when we
have Messages even if buttons are not present
---
modules/ppcp-button/resources/js/button.js | 14 +++++++++++++-
.../ContextBootstrap/SingleProductBootstap.js | 4 ++++
2 files changed, 17 insertions(+), 1 deletion(-)
diff --git a/modules/ppcp-button/resources/js/button.js b/modules/ppcp-button/resources/js/button.js
index c84825fd6..8b63b26bb 100644
--- a/modules/ppcp-button/resources/js/button.js
+++ b/modules/ppcp-button/resources/js/button.js
@@ -148,7 +148,13 @@ const bootstrap = () => {
miniCartBootstrap.init();
}
- if (context === 'product' && PayPalCommerceGateway.single_product_buttons_enabled === '1') {
+ if (
+ context === 'product'
+ && (
+ PayPalCommerceGateway.single_product_buttons_enabled === '1'
+ || hasMessages()
+ )
+ ) {
const singleProductBootstrap = new SingleProductBootstap(
PayPalCommerceGateway,
renderer,
@@ -194,6 +200,12 @@ const bootstrap = () => {
}
};
+
+const hasMessages = () => {
+ return PayPalCommerceGateway.messages.is_hidden === false
+ && document.querySelector(PayPalCommerceGateway.messages.wrapper);
+}
+
document.addEventListener(
'DOMContentLoaded',
() => {
diff --git a/modules/ppcp-button/resources/js/modules/ContextBootstrap/SingleProductBootstap.js b/modules/ppcp-button/resources/js/modules/ContextBootstrap/SingleProductBootstap.js
index 484673d71..c2a622bff 100644
--- a/modules/ppcp-button/resources/js/modules/ContextBootstrap/SingleProductBootstap.js
+++ b/modules/ppcp-button/resources/js/modules/ContextBootstrap/SingleProductBootstap.js
@@ -187,6 +187,10 @@ class SingleProductBootstap {
this.messages.renderWithAmount(data.total);
+ if ( this.gateway.single_product_buttons_enabled !== '1' ) {
+ return;
+ }
+
let enableFunding = this.gateway.url_params['enable-funding'];
let disableFunding = this.gateway.url_params['disable-funding'];