jQuery(document).ready(function($) {
function handleOutOfStockVariations() {
$('.variations_form').each(function() {
var $form = $(this);
var all_variations = $form.data('product_variations');if (!all_variations) return;$form.find('.variations select').each(function() {
var $select = $(this);
var attr_name = $select.attr('name');$select.find('option').each(function() {
var $option = $(this);
var val = $option.val();if (!val) return;var match = all_variations.find(function(v) {
return v.attributes[attr_name] === val;
});// اگر وریشنی پیدا شد که موجودی نداشت یا کلا وریشنی با این مشخصه یافت نشد
if (match) {
if (!match.is_in_stock || !match.is_purchasable) {
$option.prop('disabled', true).css('color', '#ccc');
if (!$option.text().includes(' (ناموجود)')) {
$option.text($option.text() + ' (ناموجود)');
}
} else {
$option.prop('disabled', false);
$option.text($option.text().replace(' (ناموجود)', ''));
}
}
});
});
});
}// اجرا در هنگام تغییر متغیرها و لود اولیه
$(document).on('wc_variation_form check_variations', '.variations_form', function() {
handleOutOfStockVariations();
});// اطمینان از اجرا بعد از وقفه کوتاه برای المنتور
setTimeout(handleOutOfStockVariations, 500);
});
هنوز بررسیای ثبت نشده است.