PluginProbe
MultiSafepay plugin for WooCommerce / trunk
MultiSafepay plugin for WooCommerce vtrunk
6.11.1 6.12.0 6.13.0 6.2.0 6.2.1 6.3.0 6.3.1 6.4.0 6.4.1 6.4.2 6.4.3 6.5.0 6.5.1 6.6.0 6.6.1 6.6.2 6.7.0 6.7.1 6.7.2 6.7.3 6.8.0 6.8.1 6.8.2 6.8.3 6.9.0 All 84 releases
multisafepay / src / Services / ValidationService.php

ValidationService.php in MultiSafepay plugin for WooCommerce trunk, at src/Services/ValidationService.php

50 lines 1.5 KB
No matching file
Up and down to move Enter to open Esc to close
Raw Download Zip
1 <?php declare(strict_types=1);
2
3 namespace MultiSafepay\WooCommerce\Services;
4
5 use WC_Validation;
6
7 /**
8 * Class ValidationService
9 *
10 * @package MultiSafepay\WooCommerce\Services
11 */
12 class ValidationService {
13
14 /**
15 * Validate a zip code using WooCommerce's validation method
16 *
17 * @return void
18 */
19 public function validate_postcode(): void {
20 check_ajax_referer( 'multisafepay_validator_nonce', 'security' );
21
22 $postcode = isset( $_POST['postcode'] ) ? sanitize_text_field( wp_unslash( $_POST['postcode'] ) ) : '';
23 $country = isset( $_POST['country'] ) ? sanitize_text_field( wp_unslash( $_POST['country'] ) ) : '';
24
25 // If WC_Validation is not available, consider it valid and finish
26 if ( ! class_exists( 'WC_Validation' ) || ! method_exists( 'WC_Validation', 'is_postcode' ) ) {
27 wp_send_json(
28 array(
29 'success' => true,
30 'valid' => true,
31 'error' => 'WC_Validation class not available',
32 )
33 );
34 return;
35 }
36
37 // Use the WooCommerce validation class to validate the zip code
38 $is_valid = WC_Validation::is_postcode( $postcode, $country );
39
40 wp_send_json(
41 array(
42 'success' => $is_valid,
43 'valid' => $is_valid,
44 'postcode' => $postcode,
45 'country' => $country,
46 )
47 );
48 }
49 }
50