mirror of
https://github.com/woocommerce/woocommerce-paypal-payments.git
synced 2025-09-06 14:57:26 +08:00
Add sanitize woocommerce_widget_cart_is_hidden filter for consistent values.
Remove context restrictions to mini-cart paypal buttons.
This commit is contained in:
parent
0672ca4950
commit
59a68fb604
2 changed files with 32 additions and 9 deletions
|
@ -137,7 +137,7 @@ 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,
|
||||
|
@ -147,7 +147,6 @@ const bootstrap = () => {
|
|||
|
||||
miniCartBootstrap.init();
|
||||
}
|
||||
}
|
||||
|
||||
if (context === 'product' && PayPalCommerceGateway.single_product_buttons_enabled === '1') {
|
||||
const singleProductBootstrap = new SingleProductBootstap(
|
||||
|
|
|
@ -372,6 +372,8 @@ class SmartButton implements SmartButtonInterface {
|
|||
);
|
||||
}
|
||||
|
||||
$this->sanitize_woocommerce_filters();
|
||||
|
||||
return true;
|
||||
}
|
||||
|
||||
|
@ -1522,4 +1524,26 @@ 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 {
|
||||
|
||||
// Sometimes external plugins like "woocommerce-one-page-checkout" set the $value to null.
|
||||
// Here we also disable the mini-cart on cart-block and checkout-block pages where our buttons aren't supported yet.
|
||||
add_filter( 'woocommerce_widget_cart_is_hidden', function ($value) {
|
||||
if (null === $value) {
|
||||
if ( is_product() ) {
|
||||
return false;
|
||||
}
|
||||
return in_array($this->context(), array('cart', 'checkout', 'cart-block', 'checkout-block'));
|
||||
}
|
||||
return in_array($this->context(), array('cart-block', 'checkout-block')) ? true : $value;
|
||||
}, 11);
|
||||
|
||||
}
|
||||
|
||||
}
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue