HEX
Server: LiteSpeed
System: Linux mail.aatilis.ir 6.8.0-100-generic #100-Ubuntu SMP PREEMPT_DYNAMIC Tue Jan 13 16:40:06 UTC 2026 x86_64
User: www (1000)
PHP: 8.3.30
Disabled: passthru,exec,system,putenv,chroot,chgrp,chown,shell_exec,popen,proc_open,pcntl_exec,ini_alter,ini_restore,dl,openlog,syslog,readlink,symlink,popepassthru,pcntl_alarm,pcntl_fork,pcntl_waitpid,pcntl_wait,pcntl_wifexited,pcntl_wifstopped,pcntl_wifsignaled,pcntl_wifcontinued,pcntl_wexitstatus,pcntl_wtermsig,pcntl_wstopsig,pcntl_signal,pcntl_signal_dispatch,pcntl_get_last_error,pcntl_strerror,pcntl_sigprocmask,pcntl_sigwaitinfo,pcntl_sigtimedwait,pcntl_exec,pcntl_getpriority,pcntl_setpriority,imap_open,apache_setenv
Upload Files
File: /www/wwwroot/soqatland.com/wp-content/plugins/persian-woocommerce/include/tools/class-general.php
<?php

defined( 'ABSPATH' ) || exit;

class PW_Tools_General {

	public function __construct() {
		add_filter( 'pre_get_posts', [ $this, 'fix_arabic_characters' ] );

		if ( PW()->get_options( 'fix_postcode_persian_number', 'yes' ) != 'no' ) {
			add_filter( 'woocommerce_checkout_process', [ $this, 'checkout_process_postcode' ], 20, 1 );
		}

		if ( PW()->get_options( 'postcode_validation', 'no' ) != 'no' ) {
			add_filter( 'woocommerce_validate_postcode', [ $this, 'validate_postcode' ], 10, 3 );
		}

		if ( PW()->get_options( 'fix_phone_persian_number', 'yes' ) != 'no' ) {
			add_filter( 'woocommerce_checkout_process', [ $this, 'checkout_process_phone' ], 20, 1 );
		}
	}

	public function fix_arabic_characters( $query ) {

		if ( $query->is_search ) {
			$query->set( 's', str_replace( [ 'ك', 'ي', ], [ 'ک', 'ی' ], $query->get( 's' ) ) );
		}

		return $query;
	}

	function checkout_process_postcode() {

		if ( isset( $_POST['billing_postcode'] ) ) {
			$_POST['billing_postcode'] = self::en( sanitize_text_field( $_POST['billing_postcode'] ) );
		}

		if ( isset( $_POST['shipping_postcode'] ) ) {
			$_POST['shipping_postcode'] = self::en( sanitize_text_field( $_POST['shipping_postcode'] ) );
		}

		if ( PW()->get_options( 'phone_validation', 'no' ) != 'no' ) {
			add_action( 'woocommerce_after_checkout_validation', [ $this, 'validate_phone' ], 10, 3 );
		}
	}

	public function validate_postcode( $valid, $postcode, $country ): bool {

		if ( $country != 'IR' ) {
			return $valid;
		}

		return (bool) preg_match( '/^([0-9]{10})$/', $postcode );
	}

	public function checkout_process_phone() {

		if ( isset( $_POST['billing_phone'] ) ) {
			$_POST['billing_phone'] = self::en( sanitize_text_field( $_POST['billing_phone'] ) );
		}

		if ( isset( $_POST['shipping_phone'] ) ) {
			$_POST['shipping_phone'] = self::en( sanitize_text_field( $_POST['shipping_phone'] ) );
		}

	}

	public function validate_phone( $data, $errors ) {

		if ( ! empty( $data['billing_phone'] ) && ! (bool) preg_match( '/^(\+989|989|09)[0-9]{9}$/', $data['billing_phone'] ) ) {
			$errors->add( 'validation', '<b>تلفن همراه (صورتحساب)</b> وارد شده، معتبر نمی باشد.' );
		}

		if ( ! empty( $data['shipping_phone'] ) && ! (bool) preg_match( '/^(\+989|989|09)[0-9]{9}$/', $data['shipping_phone'] ) ) {
			$errors->add( 'validation', '<b>تلفن همراه (حمل و نقل)</b> وارد شده، معتبر نمی باشد.' );
		}

	}

	private static function en( $number ) {
		$persian        = [ '۰', '۱', '۲', '۳', '۴', '۵', '۶', '۷', '۸', '۹' ];
		$arabic         = [ '٠', '١', '٢', '٣', '٤', '٥', '٦', '٧', '٨', '٩' ];
		$english_digits = range( 0, 9 );

		// Replace Persian numerals
		$number = str_replace( $persian, $english_digits, $number );

		// Replace Arabic numerals
		return str_replace( $arabic, $english_digits, $number );
	}

}

new PW_Tools_General();