// source --> https://tecweld.pl/wp-content/plugins/advanced-product-quantity/assets/js/afadvfront.js?ver=1.0 
jQuery(document).ready(function($){ 
	$(".woocommerce .products").on("click", ".quantity input", function() {
		  return false;
	});
	$(".quantity .qty").each(function() {
		var add_to_cart_button = $(this).parents( ".product" ).find(".add_to_cart_button");
 
		// For AJAX add-to-cart actions
		add_to_cart_button.attr("data-quantity", $(this).val());
 
		// For non-AJAX add-to-cart actions
		add_to_cart_button.attr("href", "?add-to-cart=" + add_to_cart_button.attr("data-product_id") + "&quantity=" + $(this).val());
	});
	$(".woocommerce .products").on("change input", ".quantity .qty", function() {
		var add_to_cart_button = $(this).parents( ".product" ).find(".add_to_cart_button");
 
		// For AJAX add-to-cart actions
		add_to_cart_button.attr("data-quantity", $(this).val());
 
		// For non-AJAX add-to-cart actions
		add_to_cart_button.attr("href", "?add-to-cart=" + add_to_cart_button.attr("data-product_id") + "&quantity=" + $(this).val());
	});
 
	// Trigger on Enter press
	$(".woocommerce .products").on("keypress", ".quantity .qty", function(e) {
		if ((e.which||e.keyCode) === 13) {
			$( this ).parents(".product").find(".add_to_cart_button").trigger("click");
		}
	});

	$("input.af-fixed-quantity").each( function(){

		$(this).attr('max', $(this).attr('min') );
	});

	if( $("select.af-single-dropdown-quantity") ) {

		$('form.cart').each( function(){

			if( $(this).closest('ul.products').length ) {
				return;
			}

			if( ! ( $(this).hasClass('grouped_form') || $(this).hasClass('variations_form') ) ) {

				$(this).find( $("input.af-dropdown-quantity") ) .replaceWith( $("select.af-single-dropdown-quantity") );

				$("select.af-single-dropdown-quantity").show();
			}
		});	
	}

	if( $("select.af-archive-dropdown-quantity") ) {

		$('form.cart').each( function(){

			if( $(this).closest('ul.products').length ) {

				if( ! ( $(this).hasClass('grouped_form') || $(this).hasClass('variations_form') ) ) {

					$(this).find( $("input.af-dropdown-quantity") ) .replaceWith( $(this).closest('li.product').find("select.af-archive-dropdown-quantity") );

					$("form.cart select.af-archive-dropdown-quantity").show();
				}
			}
		});

		$("form.cart select.af-dropdown-quantity").show();
	}
	

	$(document).ajaxComplete(function(){
		var pro_qty = $('.afadv_qnt_var_cart').prev();
		
		if (pro_qty.length > 0) {
			pro_qty.remove();
		}
	});

	var pro_qty = $('.afadv_qnt_var_cart').prev();
	
	if (pro_qty.length > 0) {
		pro_qty.remove();
	}
	
	var variation_id = $('form.variations_form').find('.variation_id').val();

	if( $('div.af-quantity-variation-' + variation_id ).length ) {

		$('form.variations_form').find('div.quantity').replaceWith( $('div.af-quantity-variation-' + variation_id ).html() );
	}

	$('form.variations_form').on('woocommerce_variation_has_changed', function(){

		if( $( this ).find('.variation_id').val() ) {

			var variation_id = $( this ).find('.variation_id').val();

			if( $('div.af-quantity-variation-' + variation_id ).length ) {

				$('form.variations_form').find('div.quantity').replaceWith( $('div.af-quantity-variation-' + variation_id ).html() );
			}
		}
	});

	$('div.af-quantity-grouped').each( function(){

		var child_id = $(this).data('child_id');

		if( $('tr#product-' + child_id ) ) {
			$('tr#product-' + child_id ).find('div.quantity').html( $(this ).html() );
		}

		$(this).remove();
	});
});
// source --> https://tecweld.pl/wp-content/plugins/woo-product-category-discount/public/js/woo-product-category-discount-public.js?ver=5.16 
jQuery(function ($) {
  if (typeof wp !== "undefined" && wp.hooks) {
    wp.hooks.addAction(
      "experimental__woocommerce_blocks-cart-set-item-quantity",
      "core/i18n",
      function (name, functionName, callback, priority) {
        setTimeout(function () {
          window.location.reload();
        }, 3000);
      },
      10
    );

    wp.hooks.addAction(
      "experimental__woocommerce_blocks-cart-remove-item",
      "core/i18n",
      function (name, functionName, callback, priority) {
        setTimeout(function () {
          window.location.reload();
        }, 3000);
      },
      10
    );
  }

  if (typeof window.wc !== "undefined" && window.wc.blocksCheckout) {
    const { registerCheckoutFilters } = window.wc.blocksCheckout;
    const wpcdCartItemClass = (defaultValue, extensions, args) => {
      const key = "_free_gift";
      const value = "yes";
      if (args && args.cartItem && args.cartItem.item_data) {
        if (WPCDHasKeyValuePair(args.cartItem.item_data, key, value)) {
          return defaultValue + "wpcd-free-gift-class";
        }
      }
      return defaultValue;
    };
    registerCheckoutFilters("woo-product-category-discount", {
      cartItemClass: wpcdCartItemClass,
    });
  }

  function WPCDHasKeyValuePair(array, key, value) {
    for (let i = 0; i < array.length; i++) {
      if (array[i].key === key && array[i].value === value) {
        return true;
      }
    }
    return false;
  }
});