HEX
Server: LiteSpeed
System: Linux cyberpanel235onubuntu2204-m-2vcpu-16gb-sgp1-01 5.15.0-94-generic #104-Ubuntu SMP Tue Jan 9 15:25:40 UTC 2024 x86_64
User: buzzb2931 (1011)
PHP: 8.0.30
Disabled: 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_get_handler,pcntl_signal_dispatch,pcntl_get_last_error,pcntl_strerror,pcntl_sigprocmask,pcntl_sigwaitinfo,pcntl_sigtimedwait,pcntl_exec,pcntl_getpriority,pcntl_setpriority,pcntl_async_signals,pcntl_unshare,
Upload Files
File: /home/buzzblu.com.bd/public_html/wp-content/themes/woodmart/js/scripts/wc/freeGiftsTable.js
jQuery.each([
	'frontend/element_ready/wd_cart_table.default',
], function(index, value) {
	woodmartThemeModule.wdElementorAddAction(value, function($wrapper) {
		woodmartThemeModule.addGiftProduct();
	});
});

// Update gist table only if turned on layout builder.
if (document.querySelector('.site-content').classList.contains('wd-builder-on')) {
	jQuery( document.body ).on( 'wc_fragment_refresh updated_wc_div', function(e) {
		var giftsWrapper = document.querySelector('.wd-fg');

		if ( ! giftsWrapper ) {
			return;
		}

		var loaderOverlay = giftsWrapper.querySelector('.wd-loader-overlay');

		if ( loaderOverlay ) {
			loaderOverlay.classList.add('wd-loading');
		}
	
		jQuery.ajax({
			url     : woodmart_settings.ajaxurl,
			data    : {
				action: 'woodmart_update_gifts_table',
			},
			method  : 'POST',
			success : function(response) {
				if (!response) {
					return;
				}

				if (giftsWrapper && response.hasOwnProperty('html')) {
					let tempDiv       = document.createElement('div');
					tempDiv.innerHTML = response.html;

					childNodes = tempDiv.querySelector('.wd-fg').childNodes;

					if (0 === childNodes.length) {
						giftsWrapper.classList.add('wd-hide');
					} else {
						giftsWrapper.classList.remove('wd-hide');
					}

					giftsWrapper.replaceChildren(...childNodes);
				}
			},
			error   : function() {
				console.log('ajax update gifts table error');
			},
			complete: function() {
				if ( loaderOverlay ) {
					loaderOverlay.classList.remove('wd-loading');
				}
			}
		});
	});
}

woodmartThemeModule.addGiftProduct = function() {
	var isBuilder = document.querySelector('.site-content').classList.contains('wd-builder-on');
	listenerArea  = isBuilder ? document.querySelector('.site-content .woocommerce') : document.querySelector('.cart-content-wrapper');

	if ( ! listenerArea ) {
		return;
	}

	listenerArea.addEventListener("click", function(e) {
		var addGiftButton = e.target.closest('.wd-add-gift-product');

		if ( addGiftButton ) {
			e.preventDefault();

			var fgTableWrapper = addGiftButton.closest('.wd-fg');
			var loaderOverlay  = fgTableWrapper.querySelector('.wd-loader-overlay');
			var productId      = addGiftButton.dataset.productId;

			if ( addGiftButton.classList.contains('wd-disabled') ) {
				return;
			}

			loaderOverlay.classList.add('wd-loading');

			jQuery.ajax({
				url     : woodmart_settings.ajaxurl,
				data    : {
					action: 'woodmart_add_gift_product',
					product_id: productId,
					security: addGiftButton.dataset.security,
				},
				method  : 'POST',
				success : function(response) {
					if (!response) {
						return;
					}

					jQuery(document.body).trigger( 'wc_update_cart' );
				},
				error   : function() {
					console.log('ajax adding gift to cart error');
				},
				complete: function() {
					loaderOverlay.classList.remove('wd-loading');
				}
			});
		}
	});
}

window.addEventListener('load',function() {
	woodmartThemeModule.addGiftProduct();
});