nation, 'state_city' ); if ( is_wp_error( $source ) || is_wp_error( $destination ) ) { return false; } $source = strval( $source->slug ?? null ); $destination = strval( $destination->slug ?? null ); return isset( $is_beside[ strtoupper( $source ) ][ strtoupper( $destination ) ] ) && $is_beside[ strtoupper( $source ) ][ strtoupper( $destination ) ] === true ? 'beside' : 'out'; } public function convert_currency_to_IRR( int $price ): int { switch ( get_woocommerce_currency() ) { case 'IRT': $price *= 10; break; case 'IRHR': $price *= 1000; break; case 'IRHT': $price *= 10000; break; } return $price; } public function convert_currency_from_IRR( int $price ): int { switch ( get_woocommerce_currency() ) { case 'IRT': $price /= 10; break; case 'IRHR': $price /= 1000; break; case 'IRHT': $price /= 10000; break; } return ceil( $price ); } // Backward compatibility public function convert_currency( int $price ): int { _doing_it_wrong( 'PWS()->convert_currency', 'Use PWS()->convert_currency_from_IRR', '4.0.0' ); return $this->convert_currency_from_IRR( $price ); } public function get_term_option( $term_id ): array { $option = get_option( 'nabik_taxonomy_' . $term_id, [] ); return apply_filters( 'pws_get_term_option', $option, $term_id ); } public function set_term_option( $term_id, array $option ) { $option = apply_filters( 'pws_set_term_option', $option, $term_id ); update_option( 'nabik_taxonomy_' . $term_id, $option ); } public function delete_term_option( $term_id ) { delete_option( 'nabik_taxonomy_' . $term_id ); } public function get_terms_option( $term_id ) { $options = wp_cache_get( 'get_terms_option_' . $term_id, 'pws' ); if ( false !== $options ) { return $options; } $ancestors = get_ancestors( $term_id, 'state_city' ); if ( empty( $ancestors ) ) { return []; } array_unshift( $ancestors, $term_id ); $options = array_map( [ $this, 'get_term_option' ], $ancestors ); wp_cache_set( 'get_terms_option_' . $term_id, $options, 'pws' ); return $options; } public static function get_option( string $option_name, $default = null ) { [ $section, $option ] = explode( '.', $option_name ); $options = get_option( 'pws_' . $section, [] ); if ( isset( $options[ $option ] ) ) { return $options[ $option ]; } return $default; } public static function set_option( string $option_name, $value ) { [ $section, $option ] = explode( '.', $option_name ); $options = get_option( 'pws_' . $section, [] ); $options = empty( $options ) ? [] : $options; $options[ $option ] = $value; update_option( 'pws_' . $section, $options ); } public function log( ...$params ) { $log = ''; $date = wp_date( 'Y-m-d' ); if ( defined( 'WC_LOG_DIR' ) ) { $log_file = WC_LOG_DIR . "pws-{$date}.log"; } else { $log_file = WP_CONTENT_DIR . "pws-{$date}.log"; } foreach ( $params as $message ) { $log .= wp_date( '[Y-m-d H:i:s] ' ); if ( is_array( $message ) || is_object( $message ) ) { $log .= print_r( $message, true ); } elseif ( is_bool( $message ) ) { $log .= ( $message ? 'true' : 'false' ); } else { $log .= $message; } $log .= PHP_EOL; } file_put_contents( $log_file, $log, FILE_APPEND ); } public static function pws_sort_state( $a, $b ) { if ( $a == $b ) { return 0; } $states = [ 'آذربایجان شرقی', 'آذربایجان غربی', 'اردبیل', 'اصفهان', 'البرز', 'ایلام', 'بوشهر', 'تهران', 'چهارمحال و بختیاری', 'خراسان جنوبی', 'خراسان رضوی', 'خراسان شمالی', 'خوزستان', 'زنجان', 'سمنان', 'سیستان و بلوچستان', 'فارس', 'قزوین', 'قم', 'کردستان', 'کرمان', 'کرمانشاه', 'کهگیلویه و بویراحمد', 'گلستان', 'گیلان', 'لرستان', 'مازندران', 'مرکزی', 'هرمزگان', 'همدان', 'یزد', ]; $a = str_replace( [ 'ي', 'ك', 'ة' ], [ 'ی', 'ک', 'ه' ], $a ); $b = str_replace( [ 'ي', 'ك', 'ة' ], [ 'ی', 'ک', 'ه' ], $b ); $a_key = array_search( trim( $a ), $states ); $b_key = array_search( trim( $b ), $states ); return $a_key < $b_key ? - 1 : 1; } public function pws_pro_url( $source ): string { return 'https://yun.ir/pws-pro?utm_source=' . esc_attr( $source ); } }