Fix context() for checkout ajax refreshes

This commit is contained in:
Alex P 2023-10-17 09:58:30 +03:00
parent 874a4e92ff
commit 9abaebf7db
No known key found for this signature in database
GPG key ID: 54487A734A204D71

View file

@ -12,6 +12,27 @@ namespace WooCommerce\PayPalCommerce\Button\Helper;
use WooCommerce\PayPalCommerce\ApiClient\Entity\OrderStatus; use WooCommerce\PayPalCommerce\ApiClient\Entity\OrderStatus;
trait ContextTrait { 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. * The current context.
@ -23,7 +44,7 @@ trait ContextTrait {
// Do this check here instead of reordering outside conditions. // Do this check here instead of reordering outside conditions.
// In order to have more control over the context. // 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'; return 'checkout';
} }
@ -47,7 +68,7 @@ trait ContextTrait {
return 'checkout-block'; return 'checkout-block';
} }
if ( ( is_checkout() ) && ! $this->is_paypal_continuation() ) { if ( $this->is_checkout() && ! $this->is_paypal_continuation() ) {
return 'checkout'; return 'checkout';
} }