【发布时间】:2017-06-05 19:03:14
【问题描述】:
我有一个包含我的产品变体(标题颜色)的下拉列表。我想在该下拉列表中添加一个标签(“选择颜色”)。我看到 Shopify 在存在多个变体时添加了一个标签,但我找不到允许我更新它的代码。
我使用的是简单的主题。
有什么帮助吗?谢谢。
【问题讨论】:
标签: javascript html css shopify
我有一个包含我的产品变体(标题颜色)的下拉列表。我想在该下拉列表中添加一个标签(“选择颜色”)。我看到 Shopify 在存在多个变体时添加了一个标签,但我找不到允许我更新它的代码。
我使用的是简单的主题。
有什么帮助吗?谢谢。
【问题讨论】:
标签: javascript html css shopify
在您的情况下,您会在 assets > theme.js.liquid 在简单主题中找到此代码。
/**
*
* Adjust option_selection.js labels based on variant default values
*
*/
Slate.simplifyVariantLabels = function (product) {
// option_selection.js does not add a label if there is only one variant option.
// Add one as long as it is not 'Title' (Shopify's default), add one.
if (product.options.length === 1 && product.options[0] !== 'Title') {
$('.selector-wrapper:eq(0)').prepend('<label for="ProductSelect-option-0">'+ product.options[0] +'</label>');
}
// Hide variant dropdown if only one exists and title contains 'Default'
if (product.variants.length && product.variants[0].title.indexOf('Default') >= 0) {
$('.selector-wrapper').hide();
}
};
【讨论】: