javascript - 检查 JS 远程替换、Shopify 中的变体可用性
问题描述
我被要求定制一个 Shopify 网站,但我在使用 Variants Dropdown 时遇到了问题,因为有一个简短的 JS 代码片段替换了主要的 Select 元素。
此片段不检查变体可用性,我不知道 JS,所以想知道是否有人有解决方案?
我尝试在 JS 代码中使用 IF 语句来实现结果,但由于某种原因它破坏了页面的标题并且不显示变体数量。
如前所述,我不了解 JS,所以希望这是相当直截了当的事情。
提前致谢。
这是指向此问题的页面的链接。 https://perfumesonline.ie/products/3614223162963?variant=31708294938676
下面是JS代码
// RENDER SIZE OPTION
var renderSizeOptions = function(options){
var sizeOptionIndex = $('.size_product__options .size_toggle').data('option-index');
var sizeSelect = $('#shopify-section-' + sectionID + ' .single-option-selector').eq(sizeOptionIndex);
var selectId = '#' + sizeSelect.attr('id');
var container = $('#shopify-section-' + sectionID + ' .size_product__options .size_toggle');
var content = '<label>' + options[sizeOptionIndex] + ':</label>';
$( selectId + ' option' ).each(function(){
var value = $(this).val();
sizeSelect.parent('.selector-wrapper').addClass('hidden');
if ( sizeSelect.val() == value ) {
return content = content + '<div class="size_item current" data-val="' + value + '"><span class="size_inner">' + value + '</span></div>';
} else {
return content = content + '<div class="size_item" data-val="' + value + '"><span class="size_inner">' + value + '</span></div>';
};
} );
container.html(content);
$('.size_product__options .size_item').on('click', function(e){
sizeSelect.val( $(this).data('val') ).trigger('change');
});
};
解决方案
推荐阅读
- .htaccess - 您如何订购在子目录中安装 Wordrpess 并强制使用 HTTPS 的重写规则?
- javascript - 如何在不使用 eval() 的情况下将变量插入路径?
- git - 如何使用 NAnt 通过 Azure DevOps 和 Git 进行构建?
- javascript - 使用 react redux 时在 axios.get(url).then() 中设置状态不起作用
- python - AttributeError:“FrozenImporter”对象没有属性“文件名”
- python - 如何对列求和以在特定行上创建第三个?
- python-3.x - Pandas strftime 24 小时格式
- c# - 在 C# Webform 中使用 OPTGROUP 初始化 SELECT2 下拉列表
- c# - 通过动态传递的任何属性和值过滤实体模型
- xml - Python中csv的特定XML解析器