diff --git a/modules/ppcp-button/src/Helper/ContextTrait.php b/modules/ppcp-button/src/Helper/ContextTrait.php index 291f5e16a..189796b75 100644 --- a/modules/ppcp-button/src/Helper/ContextTrait.php +++ b/modules/ppcp-button/src/Helper/ContextTrait.php @@ -12,6 +12,27 @@ namespace WooCommerce\PayPalCommerce\Button\Helper; use WooCommerce\PayPalCommerce\ApiClient\Entity\OrderStatus; trait ContextTrait { + /** + * Checks WC is_checkout() + WC checkout ajax requests. + */ + private function is_checkout(): bool { + if ( is_checkout() ) { + return true; + } + + /** + * The filter returning whether to detect WC checkout ajax requests. + */ + if ( apply_filters( 'ppcp_check_ajax_checkout', true ) ) { + // phpcs:ignore WordPress.Security + $wc_ajax = $_GET['wc-ajax'] ?? ''; + if ( in_array( $wc_ajax, array( 'update_order_review' ), true ) ) { + return true; + } + } + + return false; + } /** * The current context. @@ -23,7 +44,7 @@ trait ContextTrait { // Do this check here instead of reordering outside conditions. // In order to have more control over the context. - if ( ( is_checkout() ) && ! $this->is_paypal_continuation() ) { + if ( $this->is_checkout() && ! $this->is_paypal_continuation() ) { return 'checkout'; } @@ -47,7 +68,7 @@ trait ContextTrait { return 'checkout-block'; } - if ( ( is_checkout() ) && ! $this->is_paypal_continuation() ) { + if ( $this->is_checkout() && ! $this->is_paypal_continuation() ) { return 'checkout'; }