【问题标题】:Add Label to Variant Selector (Shopify)向变体选择器添加标签 (Shopify)
【发布时间】:2017-06-05 19:03:14
【问题描述】:

我有一个包含我的产品变体(标题颜色)的下拉列表。我想在该下拉列表中添加一个标签(“选择颜色”)。我看到 Shopify 在存在多个变体时添加了一个标签,但我找不到允许我更新它的代码。

我使用的是简单的主题。

有什么帮助吗?谢谢。

【问题讨论】:

    标签: javascript html css shopify


    【解决方案1】:

    在您的情况下,您会在 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();
      }
    };
    

    【讨论】:

      猜你喜欢
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 2023-03-27
      • 2023-02-15
      • 2022-01-14
      • 1970-01-01
      • 2022-07-11
      • 1970-01-01
      相关资源
      最近更新 更多