| Server IP : 89.39.208.18 / Your IP : 216.73.217.74 Web Server : LiteSpeed System : User : ( ) PHP Version : 7.4.33 Disable Function : eval,./,ln,passthru,dl,system,exec,popen,shell_exec,posix_getpwuid,posix_uname,ftp_exec,posix_uname,posix_getpwuid,posix_kill,posix_mkfifo,posix_setpgid,posix_setsid,posix_setuid,get_current_user,getmyuid,getmygid,listen,chgrp,apache_note,apache_setenv,apache_child_terminate,closelog,debugger_off,debugge_on,ini_restore,netscript,escapeshellarg,cmd,backtick,virtual,show_sourc,show_source,pclose,pcntl_exec,datasec,old_offset,ctrl_dir,ini_alter,leak,listen,chgrp,apache_setenv,define_syslog_variables,root,diskfreespace,disk_free_space,disk_total_space,posix_kill,getmyuid,getmygid,apache_child_terminate,php_ini_scanned_files,ls,ps_aux,chown,getrusage,posixc,posame,chgrp,posix_setuid,posix_setsid,posix_setgid,apache_note,apache_setenv,x_getuid,e_ini_file,nfo,SQL,mysql_li,t_dbs,filegroup,highlight_file,ilegetcontents,get_dir,popen,popens,pfsockopen,dos_conv,apache_get_modules,crack_check,crack_closedict,rar_open,bzopen,bzread,bzwrite,shellcode,posix_isatty,posix_getservbyname,escapeshellarg,hypot,pg_host,pos,posix_access,inurl,posix_times,posix_mknod,pclose,ps_fill,symlink,id,escapeshellcmd,php_uname,phpinfo MySQL : OFF | cURL : ON | WGET : ON | Perl : ON | Python : OFF | Sudo : OFF | Pkexec : OFF Directory : /home3/mahyarcake/www/wp-content/plugins/persian-woocommerce/include/tools/ |
Upload File : |
<?php
class PW_Tools_General {
public function __construct() {
add_filter( 'pre_get_posts', [ $this, 'fix_arabic_characters' ] );
if ( PW()->get_options( 'fix_load_states', 'no' ) != 'no' ) {
add_action( 'wp_footer', [ $this, 'checkout_state_dropdown_fix' ], 50 );
}
if ( PW()->get_options( 'fix_postcode_persian_number', 'no' ) != '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', 'no' ) != 'no' ) {
add_filter( 'woocommerce_checkout_process', [ $this, 'checkout_process_phone' ], 20, 1 );
}
}
function fix_arabic_characters( $query ) {
if ( $query->is_search ) {
$query->set( 's', str_replace( [ 'ك', 'ي', ], [ 'ک', 'ی' ], $query->get( 's' ) ) );
}
return $query;
}
function checkout_state_dropdown_fix() {
if ( function_exists( 'is_checkout' ) && ! is_checkout() ) {
return;
}
?>
<script>
jQuery(function () {
// Snippets.ir
jQuery('#billing_country').trigger('change');
jQuery('#billing_state_field').removeClass('woocommerce-invalid');
});
</script>
<?php
}
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 );
}
}
function validate_postcode( $valid, $postcode, $country ): bool {
if ( $country != 'IR' ) {
return $valid;
}
return (bool) preg_match( '/^([0-9]{10})$/', $postcode );
}
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'] ) );
}
}
function validate_phone( $data, $errors ) {
if ( (bool) preg_match( '/^(09[0-9]{9})$/', $data['billing_phone'] ) ) {
return false;
}
$errors->add( 'validation', '<b>تلفن همراه</b> وارد شده، معتبر نمی باشد.' );
}
private static function en( $number ) {
return str_replace( [ '۰', '۱', '۲', '۳', '۴', '۵', '۶', '۷', '۸', '۹' ], range( 0, 9 ), $number );
}
}
new PW_Tools_General();