HEX
Server: LiteSpeed
System: Linux linux31.centraldnserver.com 4.18.0-553.83.1.lve.el8.x86_64 #1 SMP Wed Nov 12 10:04:12 UTC 2025 x86_64
User: salamatk (1501)
PHP: 8.1.33
Disabled: show_source, system, shell_exec, passthru, exec, popen, proc_open
Upload Files
File: /home/salamatk/takarzan.ir/wp-content/themes/xts-luman/js/scripts/productVisitorCounter.js
/* global xts_settings */
(function($) {
	XTSThemeModule.countProductVisits = function () {
		var live_duration = 10000;

		if ( 'undefined' !== typeof xts_settings.counter_visitor_live_duration ) {
			live_duration = xts_settings.counter_visitor_live_duration;
		}

		if ('yes' === xts_settings.counter_visitor_ajax_update) {
			XTSThemeModule.updateCountProductVisits();
		} else {
			setTimeout(function() {
				XTSThemeModule.updateCountProductVisits();
			}, live_duration);
		}
	}

	XTSThemeModule.updateCountProductVisits = function() {
		$('.xts-visits-count').each( function () {
			var $this = $(this);
			var productId = $this.data('product-id');
			var count = $this.find('.xts-visits-count-number').text();

			if ( ! productId ) {
				return;
			}

			$.ajax({
				url     : xts_settings.ajaxurl,
				data    : {
					action    : 'xts_update_count_product_visits',
					product_id: productId,
					count     : count,
				},
				method  : 'POST',
				success : function(response) {
					if (response) {
						$this.find('.xts-visits-count-number').html(response.count);

						if (!response.count) {
							$this.addClass('xts-hide');
						} else {
							$this.removeClass('xts-hide');
						}

						if ('yes' === response.live_mode) {
							setTimeout(function() { XTSThemeModule.countProductVisits() }, xts_settings.counter_visitor_live_duration);
						}
					}
				},
				error   : function() {
					console.log('ajax error');
				},
				complete: function() { }
			});
		});
	};

	$(document).ready(function() {
		XTSThemeModule.countProductVisits();
	});
})(jQuery);