Код: Выделить всё
$('#product-variants .variant-card').each(function () {
const $variant = $(this);
const dependencies = ($variant.data('dependencies') || '').split(',').filter(Boolean);
const allDependenciesMet = dependencies.every(dependencyIndex => {
const dependentVariant = $('[data-variant-index="' + dependencyIndex + '"]');
const quantity = parseInt(dependentVariant.find('input[type="range"]').val(), 10) || 0;
return quantity > 0; // Check if quantity is more than 0
});
if (!allDependenciesMet) {
$variant.hide(); // Hide variant if dependencies are not met
} else {
$variant.show(); // Show variant if all dependencies are met
}
});
Я не использую никаких других плагинов, которые могут помешать этой логике, на моем локальном хосте установлен только woocommerce.
- Почему свойство display снова становится заблокированным?
- и как я могу гарантировать, что варианты останутся скрытыми, если их зависимости не соблюдаются?
Подробнее здесь: https://stackoverflow.com/questions/788 ... ing-jquery
Мобильная версия