From 6fc12a55a9134dd7e362731995483daa36110d21 Mon Sep 17 00:00:00 2001 From: Alex P Date: Mon, 30 Jan 2023 17:33:24 +0200 Subject: [PATCH] Make is_checkout()=true during validation to improve compatibility --- .../src/Validation/CheckoutFormValidator.php | 20 ++++++++++++++----- 1 file changed, 15 insertions(+), 5 deletions(-) diff --git a/modules/ppcp-button/src/Validation/CheckoutFormValidator.php b/modules/ppcp-button/src/Validation/CheckoutFormValidator.php index fd686b953..b67c96cc3 100644 --- a/modules/ppcp-button/src/Validation/CheckoutFormValidator.php +++ b/modules/ppcp-button/src/Validation/CheckoutFormValidator.php @@ -32,12 +32,22 @@ class CheckoutFormValidator extends WC_Checkout { foreach ( $data as $key => $value ) { $_POST[ $key ] = $value; } - // And we must call get_posted_data because it handles the shipping address. - $data = $this->get_posted_data(); - // It throws some notices when checking fields etc., also from other plugins via hooks. - // phpcs:ignore WordPress.PHP.NoSilencedErrors.Discouraged - @$this->validate_checkout( $data, $errors ); + $is_checkout = function () { + return true; + }; + // Some plugins/filters check is_checkout(). + add_filter( 'woocommerce_is_checkout', $is_checkout ); + try { + // And we must call get_posted_data because it handles the shipping address. + $data = $this->get_posted_data(); + + // It throws some notices when checking fields etc., also from other plugins via hooks. + // phpcs:ignore WordPress.PHP.NoSilencedErrors.Discouraged + @$this->validate_checkout( $data, $errors ); + } finally { + remove_filter( 'woocommerce_is_checkout', $is_checkout ); + } if ( $errors->has_errors() ) { throw new ValidationException( $errors->get_error_messages() );