mirror of
https://github.com/woocommerce/woocommerce-paypal-payments.git
synced 2025-09-05 08:59:14 +08:00
Merge pull request #1144 from woocommerce/pcp-1354-fix-unset-fields-validation
Make is_checkout()=true during validation to improve compatibility
This commit is contained in:
commit
94d5747fb6
1 changed files with 15 additions and 5 deletions
|
@ -32,12 +32,22 @@ class CheckoutFormValidator extends WC_Checkout {
|
||||||
foreach ( $data as $key => $value ) {
|
foreach ( $data as $key => $value ) {
|
||||||
$_POST[ $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.
|
$is_checkout = function () {
|
||||||
// phpcs:ignore WordPress.PHP.NoSilencedErrors.Discouraged
|
return true;
|
||||||
@$this->validate_checkout( $data, $errors );
|
};
|
||||||
|
// 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() ) {
|
if ( $errors->has_errors() ) {
|
||||||
throw new ValidationException( $errors->get_error_messages() );
|
throw new ValidationException( $errors->get_error_messages() );
|
||||||
|
|
Loading…
Add table
Add a link
Reference in a new issue