diff --git a/modules/ppcp-button/src/Helper/ContextTrait.php b/modules/ppcp-button/src/Helper/ContextTrait.php index a7381b1b1..db6735424 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'; }