【发布时间】:2014-12-04 08:50:57
【问题描述】:
我有一个 Shopify 产品页面,目前将我的变体显示为下拉菜单,如下所示:
但是,我想将所有可用选项(有货)显示为一组选项,如下所示。这些选项应该是可点击/可选择的:
这是下拉菜单的代码,如何将其更改为类似于上面屏幕截图的输出:
// <![CDATA[
var selectCallback = function(variant, selector) {
if (variant && variant.available == true) {
// selected a valid variant
jQuery('.button').removeClass('disabled').removeAttr('disabled'); // remove unavailable class from add-to-cart button, and re-enable button
{% if product.compare_at_price > product.price %}
jQuery('.price-field').html(Shopify.formatMoney(variant.price, "{{shop.money_format}}")); // update price field
jQuery('.price-field').addClass('sale').attr('sale', 'sale');
jQuery('.compare-field').html(Shopify.formatMoney(variant.compare_at_price, "Was {{shop.money_format}}")); // update compare field
{% else %}
jQuery('.price-field').html(Shopify.formatMoney(variant.price, "{{shop.money_format}}")); // update price field
{% endif %}
} else {
// variant doesn't exist
jQuery('.button').addClass('disabled').attr('disabled', 'disabled'); // set add-to-cart button to unavailable class and disable button
var message = variant ? "Sold Out" : "Unavailable";
jQuery('.price-field').text(message); // update price-field message
}
};
// initialize multi selector for product
jQuery(function() {
new Shopify.OptionSelectors("product-select", { product: {{ product | json }}, onVariantSelected: selectCallback });
jQuery('.selector-wrapper').addClass('clearfix');
{% if product.options.size == 1 %}
jQuery('.selector-wrapper').prepend("<label for='product-select-option-0'>{{ product.options.first }} </label>");
{% endif %}
});
// ]]>
【问题讨论】: