From 2591e4cbdf3b150897031fb364559c414227aed5 Mon Sep 17 00:00:00 2001 From: Alex P Date: Mon, 30 Oct 2023 10:10:03 +0200 Subject: [PATCH] Fix is_cart() check in ajax cart totals refresh --- .../ppcp-button/src/Helper/ContextTrait.php | 24 ++++++++++++++++++- 1 file changed, 23 insertions(+), 1 deletion(-) diff --git a/modules/ppcp-button/src/Helper/ContextTrait.php b/modules/ppcp-button/src/Helper/ContextTrait.php index 189796b75..651bf7f85 100644 --- a/modules/ppcp-button/src/Helper/ContextTrait.php +++ b/modules/ppcp-button/src/Helper/ContextTrait.php @@ -34,6 +34,28 @@ trait ContextTrait { return false; } + /** + * Checks WC is_cart() + WC cart ajax requests. + */ + private function is_cart(): bool { + if ( is_cart() ) { + return true; + } + + /** + * The filter returning whether to detect WC cart ajax requests. + */ + if ( apply_filters( 'ppcp_check_ajax_cart', true ) ) { + // phpcs:ignore WordPress.Security + $wc_ajax = $_GET['wc-ajax'] ?? ''; + if ( in_array( $wc_ajax, array( 'update_shipping_method' ), true ) ) { + return true; + } + } + + return false; + } + /** * The current context. * @@ -56,7 +78,7 @@ trait ContextTrait { return 'cart-block'; } - if ( is_cart() ) { + if ( $this->is_cart() ) { return 'cart'; }