diff --git a/modules/ppcp-button/resources/js/button.js b/modules/ppcp-button/resources/js/button.js index dfd66737b..c84825fd6 100644 --- a/modules/ppcp-button/resources/js/button.js +++ b/modules/ppcp-button/resources/js/button.js @@ -137,16 +137,15 @@ const bootstrap = () => { }; const renderer = new Renderer(creditCardRenderer, PayPalCommerceGateway, onSmartButtonClick, onSmartButtonsInit); const messageRenderer = new MessageRenderer(PayPalCommerceGateway.messages); - if (context === 'mini-cart' || context === 'product') { - if (PayPalCommerceGateway.mini_cart_buttons_enabled === '1') { - const miniCartBootstrap = new MiniCartBootstap( - PayPalCommerceGateway, - renderer, - errorHandler, - ); - miniCartBootstrap.init(); - } + if (PayPalCommerceGateway.mini_cart_buttons_enabled === '1') { + const miniCartBootstrap = new MiniCartBootstap( + PayPalCommerceGateway, + renderer, + errorHandler, + ); + + miniCartBootstrap.init(); } if (context === 'product' && PayPalCommerceGateway.single_product_buttons_enabled === '1') { diff --git a/modules/ppcp-button/src/Assets/SmartButton.php b/modules/ppcp-button/src/Assets/SmartButton.php index b40bfd266..ee2070ee8 100644 --- a/modules/ppcp-button/src/Assets/SmartButton.php +++ b/modules/ppcp-button/src/Assets/SmartButton.php @@ -373,6 +373,8 @@ class SmartButton implements SmartButtonInterface { ); } + $this->sanitize_woocommerce_filters(); + return true; } @@ -1591,4 +1593,34 @@ class SmartButton implements SmartButtonInterface { return absint( $wp->query_vars['order-pay'] ); } + + /** + * Sanitize woocommerce filter on unexpected states. + * + * @return void + */ + private function sanitize_woocommerce_filters(): void { + + add_filter( + 'woocommerce_widget_cart_is_hidden', + /** + * Sometimes external plugins like "woocommerce-one-page-checkout" set the $value to null, handle that case here. + * Here we also disable the mini-cart on cart-block and checkout-block pages where our buttons aren't supported yet. + * + * @psalm-suppress MissingClosureParamType + */ + function ( $value ) { + if ( null === $value ) { + if ( is_product() ) { + return false; + } + return in_array( $this->context(), array( 'cart', 'checkout', 'cart-block', 'checkout-block' ), true ); + } + return in_array( $this->context(), array( 'cart-block', 'checkout-block' ), true ) ? true : $value; + }, + 11 + ); + + } + }