Yêu cầu khách hàng chọn một tùy chọn
Khi khách hàng truy cập trang sản phẩm trong cửa hàng trực tuyến của bạn, mẫu mã có sẵn đầu tiên sẽ được chọn theo mặc định. Bạn có thể sử dụng tùy chỉnh này để tắt tính năng tự động chọn mẫu mã có sẵn đầu tiên. Như vậy, khách hàng sẽ được nhắc chọn mẫu mã theo cách thủ công trước khi hiển thị mẫu mã. )
Chủ đề có phân mục và không phân mục
Chọn chủ đề
Có nhiều bước tùy chỉnh khác nhau phụ thuộc vào chủ đề bạn chọn. Nhấp vào nút chủ đề của bạn trước khi thực hiện theo hướng dẫn dưới đây:
Các bước thực hiện dành cho chủ đề Boundless
Hãy thực hiện theo các bước sau để áp dụng nội dung tùy chỉnh cho chủ đề Boundless:
Chỉnh sửa tập tin JavaScript của chủ đề
Để chỉnh sửa tệp JavaScript của chủ đề:
Trong trang quản trị Shopify, vào mục Cửa hàng trực tuyến > Chủ đề.
Tìm chủ đề bạn muốn chỉnh sửa, nhấp vào nút ... để mở menu thao tác, sau đó nhấp vào Chỉnh sửa mã.
Trong ứng dụng Shopify, chạm vào Cửa hàng.
Trong phần Kênh bán hàng, chạm vào Cửa hàng trực tuyến.
Chạm vào Manage themes (Quản lý chủ đề).
Tìm chủ đề bạn muốn chỉnh sửa, nhấp vào nút ... để mở menu thao tác, sau đó nhấp vào Chỉnh sửa mã.
Trong ứng dụng Shopify, chạm vào Cửa hàng.
Trong phần Kênh bán hàng, chạm vào Cửa hàng trực tuyến.
Chạm vào Manage themes (Quản lý chủ đề).
Tìm chủ đề bạn muốn chỉnh sửa, nhấp vào nút ... để mở menu thao tác, sau đó nhấp vào Chỉnh sửa mã.
Trong thư mục Assets, nhấp vào
theme.js
hoặctheme.js.liquid
.Tìm mã
initVariantSelectors
. Bên dưới, tìm mã sau:
// Clean up variant labels if the Shopify-defined
// defaults are the only ones left
this.simplifyVariantLabels(this.productSingleObject, this.$container);
Add the following code on a new line below:
if (typeof(productOptions) != "undefined") {
for (i = 0; i < productOptions.length; i++) {
const vowels = ['a', 'e', 'i', 'o', 'u'];
const firstOptionLetter = productOptions[i][i][0].toLowerCase();
let indef = 'a';
if (vowels.includes(firstOptionLetter)) {
indef = 'an';
};
const select = document.querySelectorAll('.single-option-selector')[i];
const options = select.querySelectorAll('option');
if (options.length > 1) {
let option = new Option('Pick ' + indef + ' ' + productOptions[i][i], '');
select.add(option, select.firstChild);
select.selectedIndex = 0;
}
}
}
It should look something like this:
// Clean up variant labels if the Shopify-defined
// defaults are the only ones left
this.simplifyVariantLabels(this.productSingleObject, this.$container);
if (typeof(productOptions) != "undefined") {
for (i = 0; i < productOptions.length; i++) {
const vowels = ['a', 'e', 'i', 'o', 'u'];
const firstOptionLetter = productOptions[i][i][0].toLowerCase();
let indef = 'a';
if (vowels.includes(firstOptionLetter)) {
indef = 'an';
};
const select = document.querySelectorAll('.single-option-selector')[i];
const options = select.querySelectorAll('option');
if (options.length > 1) {
let option = new Option('Pick ' + indef + ' ' + productOptions[i][i], '');
select.add(option, select.firstChild);
select.selectedIndex = 0;
}
}
}
- Tìm dòng mã sau:
$(selectors.addToCartText).html(theme.strings.soldOut);
There are *two instances* of this line of code, both found within the `productVariantCallback` function. Replace only the *second* instance with:
$(selectors.addToCartText).html('Make a Selection');
> Note:
> Some versions of Boundless do not include the line of code to be replaced in this step. If you can't find the code, then skip to the next step.
- Nhấp vào Save (Lưu).
Sửa mẫu trang sản phẩm
Cách chỉnh sửa mẫu trang sản phẩm:
Trong thư mục Sections, chạm vào
product-template.liquid
.Tìm mã sau:
{% assign current_variant = product.selected_or_first_available_variant %}
Replace it with:
{% assign current_variant = product.selected_variant %}
- Tìm và xóa mã sau:
{% if variant == product.selected_or_first_available_variant %} selected="selected" {% endif %}
-
Tìm mã
{% schema %}
. Dán mã sau vào chính dòng của nó ở phía trên:
{% if current_variant == blank %}
<script>
var productOptions = []; {% for option in product.options -%}
var optionObj = {};
optionObj[{{ forloop.index0 }}] = "{{ product.options[forloop.index0] }}";
productOptions.push(optionObj);
{%- endfor %}
</script>
{% endif %}
It should look something like this:
{% if current_variant == blank %}
<script>
var productOptions = []; {% for option in product.options -%}
var optionObj = {};
optionObj[{{ forloop.index0 }}] = "{{ product.options[forloop.index0] }}";
productOptions.push(optionObj);
{%- endfor %}
</script>
{% endif %}
{% schema %}
- Nhấp vào Save (Lưu).
Thay đổi cài đặt ngôn ngữ cho nút Thêm vào giỏ hàng
Bạn có thể thay đổi cài đặt ngôn ngữ cho nút Thêm vào giỏ hàng để các sản phẩm không hiển thị là "Không có" trước khi thao tác lựa chọn được thực hiện.
- Trong phần Shopify admin (Quản trị viên Shopify), vào mục Cửa hàng trực tuyến > Chủ đề.
- Trong ứng dụng Shopify, chạm vào Cửa hàng.
- Trong phần Sales channels (Kênh bán hàng), nhấn vào Cửa hàng trực tuyến.
- Nhấn vào Manage themes (Quản lý chủ đề).
- Trong ứng dụng Shopify, chạm vào Cửa hàng.
- Trong phần Sales channels (Kênh bán hàng), nhấn vào Cửa hàng trực tuyến.
- Nhấn vào Manage themes (Quản lý chủ đề).
Tìm chủ đề bạn muốn chỉnh sửa rồi nhấp vào Thao tác > Chỉnh sửa nội dung chủ đề mặc định.
Trong hộp Lọc, bắt đầu nhập
unavailable
để hiển thị bản dịch của từ "Unavailable".Thay thế từ Unavailable thành
Make a selection
.Nhấp vào Save (Lưu).
Các bước thực hiện dành cho chủ đề Khai trương
Hãy thực hiện theo các bước sau để áp dụng nội dung tùy chỉnh cho chủ đề Khai trương:
Chỉnh sửa tập tin JavaScript của chủ đề
Để chỉnh sửa tệp JavaScript của chủ đề:
Trong trang quản trị Shopify, vào mục Cửa hàng trực tuyến > Chủ đề.
Tìm chủ đề bạn muốn chỉnh sửa, nhấp vào nút ... để mở menu thao tác, sau đó nhấp vào Chỉnh sửa mã.
Trong ứng dụng Shopify, chạm vào Cửa hàng.
Trong phần Kênh bán hàng, chạm vào Cửa hàng trực tuyến.
Chạm vào Manage themes (Quản lý chủ đề).
Tìm chủ đề bạn muốn chỉnh sửa, nhấp vào nút ... để mở menu thao tác, sau đó nhấp vào Chỉnh sửa mã.
Trong ứng dụng Shopify, chạm vào Cửa hàng.
Trong phần Kênh bán hàng, chạm vào Cửa hàng trực tuyến.
Chạm vào Manage themes (Quản lý chủ đề).
Tìm chủ đề bạn muốn chỉnh sửa, nhấp vào nút ... để mở menu thao tác, sau đó nhấp vào Chỉnh sửa mã.
Trong thư mục Assets, nhấp vào
theme.js
hoặctheme.js.liquid
.Thêm mã sau vào cuối tệp:
(function() {
if (typeof(productOptions) != "undefined") {
for (i = 0; i < productOptions.length; i++) {
const vowels = ['a', 'e', 'i', 'o', 'u'];
const firstOptionLetter = productOptions[i][i][0].toLowerCase();
let indef = 'a';
if (vowels.includes(firstOptionLetter)) {
indef = 'an';
};
const select = document.querySelectorAll('.single-option-selector')[i];
const options = select.querySelectorAll('option');
if (options.length > 1) {
let option = new Option('Pick ' + indef + ' ' + productOptions[i][i], '');
select.add(option, select.firstChild);
select.selectedIndex = 0;
}
}
}
})();
-
Tìm mã
_updatePrice: function(variant)
. Thay mã sau:
if (
variant.price === this.currentVariant.price &&
variant.compare_at_price === this.currentVariant.compare_at_price &&
variant.unit_price === this.currentVariant.unit_price
) {
return;
}
with:
/* if (
variant.price === this.currentVariant.price &&
variant.compare_at_price === this.currentVariant.compare_at_price &&
variant.unit_price === this.currentVariant.unit_price
) {
return;
} */
If you can't find the above code, then find the following code:
if (
variant.price === this.currentVariant.price &&
variant.compare_at_price === this.currentVariant.compare_at_price
) {
return;
}
Replace it with:
/* if (
variant.price === this.currentVariant.price &&
variant.compare_at_price === this.currentVariant.compare_at_price
) {
return;
} */
-
Tìm mã
this.currentVariant = variant;
this._updatePaymentButton(variant);
The result should look something like this:
this.currentVariant = variant;
this._updatePaymentButton(variant);
-
Tìm mã
_updateImages: function(variant)
. Thay mã sau:
var currentVariantImage = this.currentVariant.featured_image || {};
with:
if (this.currentVariant != undefined) {
var currentVariantImage = this.currentVariant.featured_image || {};
}
- Ngay bên dưới, tìm mã sau:
if (
!variant.featured_image ||
variantImage.src === currentVariantImage.src
) {
return;
}
Replace it with:
/* if (
!variant.featured_image ||
variantImage.src === currentVariantImage.src
) {
return;
} */
-
Tìm mã
_updateSKU: function(variant)
. Thay mã sau:
if (variant.sku === this.currentVariant.sku) {
return;
}
with:
if (this.currentVariant != undefined ) {
if (variant.sku === this.currentVariant.sku) {
return;
}
}
-
Tìm mã
_initVariants: function() {
. Thay mã sau:
if (this.storeAvailability && this.variants.currentVariant.available) {
this.storeAvailability.updateContent(this.variants.currentVariant.id);
}
with:
/* if (this.storeAvailability && this.variants.currentVariant.available) {
this.storeAvailability.updateContent(this.variants.currentVariant.id);
} */
> Note:
> This code only needs to be replaced in Debut version 17.5.0 and above.
- Tìm mã sau:
_updateSKU: function(variant) {
if (this.currentVariant != undefined ) {
if (variant.sku === this.currentVariant.sku) {
return;
}
}
this.container.dispatchEvent(
new CustomEvent('variantSKUChange', {
detail: {
variant: variant
},
bubbles: true,
cancelable: true
})
);
},
Add the following code, on a new line, below the above code:
_updatePaymentButton: function(variant) {
if (this.currentVariant != undefined) {
const paymentButton = document.querySelector('.payment-button');
if (paymentButton) {
paymentButton.removeAttribute('class', 'visually-hidden');
}
} else {
document.querySelector('.payment-button').setAttribute('class', 'visually-hidden');
}
},
It should look something like this:
_updateSKU: function(variant) {
if (this.currentVariant != undefined ) {
if (variant.sku === this.currentVariant.sku) {
return;
}
}
this.container.dispatchEvent(
new CustomEvent('variantSKUChange', {
detail: {
variant: variant
},
bubbles: true,
cancelable: true
})
);
},
_updatePaymentButton: function(variant) {
if (this.currentVariant != undefined) {
const paymentButton = document.querySelector('.payment-button');
if (paymentButton) {
paymentButton.removeAttribute('class', 'visually-hidden');
}
} else {
document.querySelector('.payment-button').setAttribute('class', 'visually-hidden');
}
},
- Nhấp vào Save (Lưu).
Sửa mẫu trang sản phẩm
Cách chỉnh sửa mẫu trang sản phẩm:
Trong thư mục Sections, chạm vào
product-template.liquid
.Tìm mã sau:
{%- assign current_variant = product.selected_or_first_available_variant -%}
Replace it with:
{%- if product.variants.size > 1 -%}
{%- assign current_variant = product.selected_variant -%}
{%- else %}
{%- assign current_variant = product.first_available_variant -%}
{%- endif %}
- Tìm và xóa mã sau:
{% if variant == product.selected_or_first_available_variant %} selected="selected" {% endif %}
If you can't find the code above, then find this code and delete it:
{%- if variant == current_variant %} selected="selected" {%- endif -%}
- Tìm mã sau:
{%- assign featured_image = product.selected_or_first_available_variant.featured_image | default: product.featured_image -%}
Replace it with:
{%- assign featured_image = current_variant.featured_image | default: product.featured_image -%}
If you can't find the code above, then find this code:
{%- assign featured_media = product.selected_or_first_available_variant.featured_media | default: product.featured_media -%}
Replace it with:
{%- assign featured_media = current_variant.featured_media | default: product.featured_media -%}
> Note:
> Some versions of Debut do not include the line of code to be replaced in this step. If you can't find the code, then skip to the next step.
- Tìm mã sau:
{% unless current_variant.available %}
{{ 'products.product.sold_out' | t }}
{% else %}
{{ 'products.product.add_to_cart' | t }}
{% endunless %}
Replace it with:
{% if current_variant == blank %}
{{ 'products.product.unavailable' | t }}
{% elsif current_variant.available %}
{{ 'products.product.add_to_cart' | t }}
{% else %}
{{ 'products.product.sold_out' | t }}
{% endif %}
- Tìm mã sau:
{% if section.settings.enable_payment_button %}
{{ form | payment_button }}
{% endif %}
Replace it with:
<div class="payment-button {% if current_variant == blank %}visually-hidden {% endif %}">
{% if section.settings.enable_payment_button %}
{{ form | payment_button }}
{% endif %}
</div>
-
Tìm mã
{% schema %}
. Dán mã sau vào chính dòng của nó ở phía trên:
{% if current_variant == blank %}
<script>
var productOptions = []; {% for option in product.options -%}
var optionObj = {};
optionObj[{{ forloop.index0 }}] = "{{ product.options[forloop.index0] }}";
productOptions.push(optionObj);
{%- endfor %}
</script>
{% endif %}
It should look something like this:
{% if current_variant == blank %}
<script>
var productOptions = []; {% for option in product.options -%}
var optionObj = {};
optionObj[{{ forloop.index0 }}] = "{{ product.options[forloop.index0] }}";
productOptions.push(optionObj);
{%- endfor %}
</script>
{% endif %}
{% schema %}
- Nhấp vào Save (Lưu).
Sửa đoạn mã giá sản phẩm
Để sửa đoạn mã giá sản phẩm:
Trong thư mục Snippets (Đoạn mã), nhấp vào
product-price.liquid
.Tìm mã sau:
{%- liquid
if variant.title
assign compare_at_price = variant.compare_at_price
assign price = variant.price
assign available = variant.available
else
assign compare_at_price = 1999
assign price = 1999
assign available = true
endif assign money_price = price | money
-%}
Replace it with:
{%- liquid
if variant.title
assign compare_at_price = variant.compare_at_price
assign price = variant.price
assign available = variant.available
elsif product.title
assign compare_at_price = product.compare_at_price
assign price = product.price
assign available = product.available
else
assign compare_at_price = 1999
assign price = 1999
assign available = true
endif assign money_price = price | money
-%}
> Note:
> Some versions of Debut do not include the code to be replaced in this step. If you can't find the code, then skip to the next step.
Thay đổi cài đặt ngôn ngữ cho nút Thêm vào giỏ hàng
Bạn có thể thay đổi cài đặt ngôn ngữ cho nút Thêm vào giỏ hàng để các sản phẩm không hiển thị là "Không có" trước khi thao tác lựa chọn được thực hiện.
- Trong phần Shopify admin (Quản trị viên Shopify), vào mục Cửa hàng trực tuyến > Chủ đề.
- Trong ứng dụng Shopify, chạm vào Cửa hàng.
- Trong phần Sales channels (Kênh bán hàng), nhấn vào Cửa hàng trực tuyến.
- Nhấn vào Manage themes (Quản lý chủ đề).
- Trong ứng dụng Shopify, chạm vào Cửa hàng.
- Trong phần Sales channels (Kênh bán hàng), nhấn vào Cửa hàng trực tuyến.
- Nhấn vào Manage themes (Quản lý chủ đề).
Tìm chủ đề bạn muốn chỉnh sửa rồi nhấp vào Thao tác > Chỉnh sửa nội dung chủ đề mặc định.
Trong hộp Lọc, bắt đầu nhập
unavailable
để hiển thị bản dịch của từ "Unavailable".Thay thế từ Unavailable thành
Make a selection
.Nhấp vào Save (Lưu).
Các bước thực hiện dành cho chủ đề Minimal
Hãy thực hiện theo các bước sau để áp dụng nội dung tùy chỉnh cho chủ đề Minimal:
Chỉnh sửa tập tin JavaScript của chủ đề
Để chỉnh sửa tệp JavaScript của chủ đề:
Trong trang quản trị Shopify, vào mục Cửa hàng trực tuyến > Chủ đề.
Tìm chủ đề bạn muốn chỉnh sửa, nhấp vào nút ... để mở menu thao tác, sau đó nhấp vào Chỉnh sửa mã.
Trong ứng dụng Shopify, chạm vào Cửa hàng.
Trong phần Kênh bán hàng, chạm vào Cửa hàng trực tuyến.
Chạm vào Manage themes (Quản lý chủ đề).
Tìm chủ đề bạn muốn chỉnh sửa, nhấp vào nút ... để mở menu thao tác, sau đó nhấp vào Chỉnh sửa mã.
Trong ứng dụng Shopify, chạm vào Cửa hàng.
Trong phần Kênh bán hàng, chạm vào Cửa hàng trực tuyến.
Chạm vào Manage themes (Quản lý chủ đề).
Tìm chủ đề bạn muốn chỉnh sửa, nhấp vào nút ... để mở menu thao tác, sau đó nhấp vào Chỉnh sửa mã.
Trong thư mục Assets, nhấp vào
theme.js
hoặctheme.js.liquid
.Tìm mã
initProductVariant: function() {
. Bên dưới, tìm mã sau:
// Hide selectors if we only have 1 variant and its title contains 'Default'.
if (
product.variants.length === 1 &&
product.variants[0].title.toLowerCase().indexOf('default') !== -1
) {
$('.selector-wrapper', this.$container).hide();
}
Add the following code on a new line below:
if (typeof(productOptions) != "undefined") {
for (i = 0; i < productOptions.length; i++) {
const vowels = ['a', 'e', 'i', 'o', 'u'];
const firstOptionLetter = productOptions[i][i][0].toLowerCase();
let indef = 'a';
if (vowels.includes(firstOptionLetter)) {
indef = 'an';
};
const select = document.querySelectorAll('.single-option-selector')[i];
const options = select.querySelectorAll('option');
if (options.length > 1) {
let option = new Option('Pick ' + indef + ' ' + productOptions[i][i], '');
select.add(option, select.firstChild);
select.selectedIndex = 0;
}
}
}
It should look something like this:
// Hide selectors if we only have 1 variant and its title contains 'Default'.
if (
product.variants.length === 1 &&
product.variants[0].title.toLowerCase().indexOf('default') !== -1
) {
$('.selector-wrapper', this.$container).hide();
}
if (typeof(productOptions) != "undefined") {
for (i = 0; i < productOptions.length; i++) {
const vowels = ['a', 'e', 'i', 'o', 'u'];
const firstOptionLetter = productOptions[i][i][0].toLowerCase();
let indef = 'a';
if (vowels.includes(firstOptionLetter)) {
indef = 'an';
};
const select = document.querySelectorAll('.single-option-selector')[i];
const options = select.querySelectorAll('option');
if (options.length > 1) {
let option = new Option('Pick ' + indef + ' ' + productOptions[i][i], '');
select.add(option, select.firstChild);
select.selectedIndex = 0;
}
}
}
- Nhấp vào Save (Lưu).
Chỉnh sửa mẫu trang sản phẩm:
Cách chỉnh sửa mẫu trang sản phẩm:
Trong thư mục Sections, chạm vào
product-template.liquid
.Tìm mã sau:
{% assign variant = product.selected_or_first_available_variant %}
Replace it with:
{% assign variant = product.selected_variant %}
- Tìm và xóa mã sau:
{% if variant == product.selected_or_first_available_variant %} selected="selected" {% endif %}
- Tìm tất cả các lần xuất hiện của mã sau:
{% assign featured_image = product.selected_or_first_available_variant.featured_image | default: product.featured_image %}
Replace with:
{% assign featured_image = product.selected_variant.featured_image | default: product.featured_image %}
-
Tìm mã
{% schema %}
. Dán mã sau vào chính dòng của nó ở phía trên:
{% if current_variant == blank %}
<script>
var productOptions = []; {% for option in product.options -%}
var optionObj = {};
optionObj[{{ forloop.index0 }}] = "{{ product.options[forloop.index0] }}";
productOptions.push(optionObj);
{%- endfor %}
</script>
{% endif %}
It should look something like this:
{% if current_variant == blank %}
<script>
var productOptions = []; {% for option in product.options -%}
var optionObj = {};
optionObj[{{ forloop.index0 }}] = "{{ product.options[forloop.index0] }}";
productOptions.push(optionObj);
{%- endfor %}
</script>
{% endif %}
{% schema %}
- Nhấp vào Save (Lưu).
Thay đổi cài đặt ngôn ngữ cho nút Thêm vào giỏ hàng
Bạn có thể thay đổi cài đặt ngôn ngữ cho nút Thêm vào giỏ hàng để các sản phẩm không hiển thị là "Không có" trước khi thao tác lựa chọn được thực hiện.
- Trong phần Shopify admin (Quản trị viên Shopify), vào mục Cửa hàng trực tuyến > Chủ đề.
- Trong ứng dụng Shopify, chạm vào Cửa hàng.
- Trong phần Sales channels (Kênh bán hàng), nhấn vào Cửa hàng trực tuyến.
- Nhấn vào Manage themes (Quản lý chủ đề).
- Trong ứng dụng Shopify, chạm vào Cửa hàng.
- Trong phần Sales channels (Kênh bán hàng), nhấn vào Cửa hàng trực tuyến.
- Nhấn vào Manage themes (Quản lý chủ đề).
Tìm chủ đề bạn muốn chỉnh sửa rồi nhấp vào Thao tác > Chỉnh sửa nội dung chủ đề mặc định.
Trong hộp Lọc, bắt đầu nhập
unavailable
để hiển thị bản dịch của từ "Unavailable".Thay thế từ Unavailable thành
Make a selection
.Nhấp vào Save (Lưu).
Các bước thực hiện dành cho chủ đề Narrative
Hãy thực hiện theo các bước sau để áp dụng nội dung tùy chỉnh cho chủ đề Narrative:
Chỉnh sửa tập tin JavaScript của chủ đề
Để chỉnh sửa tệp JavaScript của chủ đề:
Trong trang quản trị Shopify, vào mục Cửa hàng trực tuyến > Chủ đề.
Tìm chủ đề bạn muốn chỉnh sửa, nhấp vào nút ... để mở menu thao tác, sau đó nhấp vào Chỉnh sửa mã.
Trong ứng dụng Shopify, chạm vào Cửa hàng.
Trong phần Kênh bán hàng, chạm vào Cửa hàng trực tuyến.
Chạm vào Manage themes (Quản lý chủ đề).
Tìm chủ đề bạn muốn chỉnh sửa, nhấp vào nút ... để mở menu thao tác, sau đó nhấp vào Chỉnh sửa mã.
Trong ứng dụng Shopify, chạm vào Cửa hàng.
Trong phần Kênh bán hàng, chạm vào Cửa hàng trực tuyến.
Chạm vào Manage themes (Quản lý chủ đề).
Tìm chủ đề bạn muốn chỉnh sửa, nhấp vào nút ... để mở menu thao tác, sau đó nhấp vào Chỉnh sửa mã.
Trong thư mục Assets, nhấp vào
custom.js
.Thêm mã sau vào cuối tệp:
(function() {
if (typeof(productOptions) != "undefined") {
for (i = 0; i < productOptions.length; i++) {
const vowels = ['a', 'e', 'i', 'o', 'u'];
const firstOptionLetter = productOptions[i][i][0].toLowerCase();
let indef = 'a';
if (vowels.includes(firstOptionLetter)) {
indef = 'an';
};
const select = document.querySelectorAll('.single-option-selector')[i];
const options = select.querySelectorAll('option');
if (options.length > 1) {
let option = new Option('Pick ' + indef + ' ' + productOptions[i][i], '');
select.add(option, select.firstChild);
select.selectedIndex = 0;
}
}
}
})();
- Nhấp vào Save (Lưu).
Sửa mẫu trang sản phẩm
Cách chỉnh sửa mẫu trang sản phẩm:
Trong thư mục Sections, chạm vào
product-template.liquid
.Tìm mã sau:
{%- assign current_variant = product.selected_or_first_available_variant -%}
Replace it with:
{%- if product.variants.size > 1 -%}
{%- assign current_variant = product.selected_variant -%}
{%- else -%}
{%- assign current_variant = product.first_available_variant -%}
{%- endif -%}
-
Tìm mã
{% schema %}
. Dán mã sau vào chính dòng của nó ở phía trên:
{% if current_variant == blank %}
<script>
var productOptions = []; {% for option in product.options -%}
var optionObj = {};
optionObj[{{ forloop.index0 }}] = "{{ product.options[forloop.index0] }}";
productOptions.push(optionObj);
{%- endfor %}
</script>
{% endif %}
It should look something like this:
{% if current_variant == blank %}
<script>
var productOptions = []; {% for option in product.options -%}
var optionObj = {};
optionObj[{{ forloop.index0 }}] = "{{ product.options[forloop.index0] }}";
productOptions.push(optionObj);
{%- endfor %}
</script>
{% endif %}
{% schema %}
- Nhấp vào Save (Lưu).
Thay đổi cài đặt ngôn ngữ cho nút Thêm vào giỏ hàng
Bạn có thể thay đổi cài đặt ngôn ngữ cho nút Thêm vào giỏ hàng để các sản phẩm không hiển thị là "Không có" trước khi thao tác lựa chọn được thực hiện.
- Trong phần Shopify admin (Quản trị viên Shopify), vào mục Cửa hàng trực tuyến > Chủ đề.
- Trong ứng dụng Shopify, chạm vào Cửa hàng.
- Trong phần Sales channels (Kênh bán hàng), nhấn vào Cửa hàng trực tuyến.
- Nhấn vào Manage themes (Quản lý chủ đề).
- Trong ứng dụng Shopify, chạm vào Cửa hàng.
- Trong phần Sales channels (Kênh bán hàng), nhấn vào Cửa hàng trực tuyến.
- Nhấn vào Manage themes (Quản lý chủ đề).
Tìm chủ đề bạn muốn chỉnh sửa rồi nhấp vào Thao tác > Chỉnh sửa nội dung chủ đề mặc định.
Trong hộp Lọc, bắt đầu nhập
unavailable
để hiển thị bản dịch của từ "Unavailable".Thay thế từ Unavailable thành
Make a selection
.Nhấp vào Save (Lưu).
Các bước thực hiện dành cho chủ đề Simple
Hãy thực hiện theo các bước sau để áp dụng nội dung tùy chỉnh cho chủ đề Simple:
Chỉnh sửa tập tin JavaScript của chủ đề
Để chỉnh sửa tệp JavaScript của chủ đề:
Trong trang quản trị Shopify, vào mục Cửa hàng trực tuyến > Chủ đề.
Tìm chủ đề bạn muốn chỉnh sửa, nhấp vào nút ... để mở menu thao tác, sau đó nhấp vào Chỉnh sửa mã.
Trong ứng dụng Shopify, chạm vào Cửa hàng.
Trong phần Kênh bán hàng, chạm vào Cửa hàng trực tuyến.
Chạm vào Manage themes (Quản lý chủ đề).
Tìm chủ đề bạn muốn chỉnh sửa, nhấp vào nút ... để mở menu thao tác, sau đó nhấp vào Chỉnh sửa mã.
Trong ứng dụng Shopify, chạm vào Cửa hàng.
Trong phần Kênh bán hàng, chạm vào Cửa hàng trực tuyến.
Chạm vào Manage themes (Quản lý chủ đề).
Tìm chủ đề bạn muốn chỉnh sửa, nhấp vào nút ... để mở menu thao tác, sau đó nhấp vào Chỉnh sửa mã.
Trong thư mục Assets, nhấp vào
theme.js
hoặctheme.js.liquid
.Tìm mã
initProductVariant: function() {
. Bên dưới, tìm mã sau:
// Clean up variant labels if the Shopify-defined
// defaults are the only ones left
Slate.simplifyVariantLabels(this.productSingleObject, this.$container);
Add the following code on a new line below:
if (typeof(productOptions) != "undefined") {
for (i = 0; i < productOptions.length; i++) {
const vowels = ['a', 'e', 'i', 'o', 'u'];
const firstOptionLetter = productOptions[i][i][0].toLowerCase();
let indef = 'a';
if (vowels.includes(firstOptionLetter)) {
indef = 'an';
};
const select = document.querySelectorAll('.single-option-selector')[i];
const options = select.querySelectorAll('option');
if (options.length > 1) {
let option = new Option('Pick ' + indef + ' ' + productOptions[i][i], '');
select.add(option, select.firstChild);
select.selectedIndex = 0;
}
}
}
It should look something like this:
// Clean up variant labels if the Shopify-defined
// defaults are the only ones left
Slate.simplifyVariantLabels(this.productSingleObject, this.$container);
if (typeof(productOptions) != "undefined") {
for (i = 0; i < productOptions.length; i++) {
const vowels = ['a', 'e', 'i', 'o', 'u'];
const firstOptionLetter = productOptions[i][i][0].toLowerCase();
let indef = 'a';
if (vowels.includes(firstOptionLetter)) {
indef = 'an';
};
const select = document.querySelectorAll('.single-option-selector')[i];
const options = select.querySelectorAll('option');
if (options.length > 1) {
let option = new Option('Pick ' + indef + ' ' + productOptions[i][i], '');
select.add(option, select.firstChild);
select.selectedIndex = 0;
}
}
}
- Nhấp vào Save (Lưu).
Sửa mẫu trang sản phẩm
Cách chỉnh sửa mẫu trang sản phẩm:
Trong thư mục Sections, chạm vào
product-template.liquid
.Tìm mã sau:
{% assign current_variant = product.selected_or_first_available_variant %}
Replace it with:
{% assign current_variant = product.selected_variant %}
- Tìm và xóa mã sau:
{% if variant == product.selected_or_first_available_variant %} selected="selected" {% endif %}
-
Tìm mã
{% schema %}
. Dán mã sau vào chính dòng của nó ở phía trên:
{% if current_variant == blank %}
<script>
var productOptions = []; {% for option in product.options -%}
var optionObj = {};
optionObj[{{ forloop.index0 }}] = "{{ product.options[forloop.index0] }}";
productOptions.push(optionObj);
{%- endfor %}
</script>
{% endif %}
It should look something like this:
{% if current_variant == blank %}
<script>
var productOptions = []; {% for option in product.options -%}
var optionObj = {};
optionObj[{{ forloop.index0 }}] = "{{ product.options[forloop.index0] }}";
productOptions.push(optionObj);
{%- endfor %}
</script>
{% endif %}
{% schema %}
- Nhấp vào Save (Lưu).
Thay đổi cài đặt ngôn ngữ cho nút Thêm vào giỏ hàng
Bạn có thể thay đổi cài đặt ngôn ngữ cho nút Thêm vào giỏ hàng để các sản phẩm không hiển thị là "Không có" trước khi thao tác lựa chọn được thực hiện.
- Trong phần Shopify admin (Quản trị viên Shopify), vào mục Cửa hàng trực tuyến > Chủ đề.
- Trong ứng dụng Shopify, chạm vào Cửa hàng.
- Trong phần Sales channels (Kênh bán hàng), nhấn vào Cửa hàng trực tuyến.
- Nhấn vào Manage themes (Quản lý chủ đề).
- Trong ứng dụng Shopify, chạm vào Cửa hàng.
- Trong phần Sales channels (Kênh bán hàng), nhấn vào Cửa hàng trực tuyến.
- Nhấn vào Manage themes (Quản lý chủ đề).
Tìm chủ đề bạn muốn chỉnh sửa rồi nhấp vào Thao tác > Chỉnh sửa nội dung chủ đề mặc định.
Trong hộp Lọc, bắt đầu nhập
unavailable
để hiển thị bản dịch của từ "Unavailable".Thay thế từ Unavailable thành
Make a selection
.Nhấp vào Save (Lưu).
Các bước thực hiện dành cho chủ đề Cung ứng
Hãy thực hiện theo các bước sau để áp dụng nội dung tùy chỉnh cho chủ đề Supply:
Chỉnh sửa tập tin JavaScript của chủ đề
Để chỉnh sửa tệp JavaScript của chủ đề:
Trong trang quản trị Shopify, vào mục Cửa hàng trực tuyến > Chủ đề.
Tìm chủ đề bạn muốn chỉnh sửa, nhấp vào nút ... để mở menu thao tác, sau đó nhấp vào Chỉnh sửa mã.
Trong ứng dụng Shopify, chạm vào Cửa hàng.
Trong phần Kênh bán hàng, chạm vào Cửa hàng trực tuyến.
Chạm vào Manage themes (Quản lý chủ đề).
Tìm chủ đề bạn muốn chỉnh sửa, nhấp vào nút ... để mở menu thao tác, sau đó nhấp vào Chỉnh sửa mã.
Trong ứng dụng Shopify, chạm vào Cửa hàng.
Trong phần Kênh bán hàng, chạm vào Cửa hàng trực tuyến.
Chạm vào Manage themes (Quản lý chủ đề).
Tìm chủ đề bạn muốn chỉnh sửa, nhấp vào nút ... để mở menu thao tác, sau đó nhấp vào Chỉnh sửa mã.
Trong thư mục Assets, nhấp vào
theme.js
hoặctheme.js.liquid
.Tìm mã
initProductVariant: function() {
. Bên dưới, tìm mã sau:
// Clean up variant labels if the Shopify-defined
// defaults are the only ones left
this.simplifyVariantLabels(this.productSingleObject);
Add the following code on a new line below:
if (typeof(productOptions) != "undefined") {
for (i = 0; i < productOptions.length; i++) {
const vowels = ['a', 'e', 'i', 'o', 'u'];
const firstOptionLetter = productOptions[i][i][0].toLowerCase();
let indef = 'a';
if (vowels.includes(firstOptionLetter)) {
indef = 'an';
};
const select = document.querySelectorAll('.single-option-selector')[i];
const options = select.querySelectorAll('option');
if (options.length > 1) {
let option = new Option('Pick ' + indef + ' ' + productOptions[i][i], '');
select.add(option, select.firstChild);
select.selectedIndex = 0;
}
}
}
It should look something like this:
// Clean up variant labels if the Shopify-defined
// defaults are the only ones left
this.simplifyVariantLabels(this.productSingleObject);
if (typeof(productOptions) != "undefined") {
for (i = 0; i < productOptions.length; i++) {
const vowels = ['a', 'e', 'i', 'o', 'u'];
const firstOptionLetter = productOptions[i][i][0].toLowerCase();
let indef = 'a';
if (vowels.includes(firstOptionLetter)) {
indef = 'an';
};
const select = document.querySelectorAll('.single-option-selector')[i];
const options = select.querySelectorAll('option');
if (options.length > 1) {
let option = new Option('Pick ' + indef + ' ' + productOptions[i][i], '');
select.add(option, select.firstChild);
select.selectedIndex = 0;
}
}
}
- Nhấp vào Save (Lưu).
Sửa mẫu trang sản phẩm
Cách chỉnh sửa mẫu trang sản phẩm:
Trong thư mục Sections, chạm vào
product-template.liquid
.Tìm mã sau:
{% assign variant = product.selected_or_first_available_variant %}
Replace it with:
{% assign variant = product.selected_variant %}
- Tìm và xóa mã sau:
{% if variant == product.selected_or_first_available_variant %} selected="selected" {% endif %}
- Tìm tất cả các lần xuất hiện của mã sau:
{% assign featured_image = product.selected_or_first_available_variant.featured_image | default: product.featured_image %}
Replace it with:
{% assign featured_image = product.selected_variant.featured_image | default: product.featured_image %}
-
Tìm mã
{% schema %}
. Dán mã sau vào chính dòng của nó ở phía trên:
{% if current_variant == blank %}
<script>
var productOptions = []; {% for option in product.options -%}
var optionObj = {};
optionObj[{{ forloop.index0 }}] = "{{ product.options[forloop.index0] }}";
productOptions.push(optionObj);
{%- endfor %}
</script>
{% endif %}
It should look something like this:
{% if current_variant == blank %}
<script>
var productOptions = []; {% for option in product.options -%}
var optionObj = {};
optionObj[{{ forloop.index0 }}] = "{{ product.options[forloop.index0] }}";
productOptions.push(optionObj);
{%- endfor %}
</script>
{% endif %}
{% schema %}
- Nhấp vào Save (Lưu).
Thay đổi cài đặt ngôn ngữ cho nút Thêm vào giỏ hàng
Bạn có thể thay đổi cài đặt ngôn ngữ cho nút Thêm vào giỏ hàng để các sản phẩm không hiển thị là "Không có" trước khi thao tác lựa chọn được thực hiện.
- Trong phần Shopify admin (Quản trị viên Shopify), vào mục Cửa hàng trực tuyến > Chủ đề.
- Trong ứng dụng Shopify, chạm vào Cửa hàng.
- Trong phần Sales channels (Kênh bán hàng), nhấn vào Cửa hàng trực tuyến.
- Nhấn vào Manage themes (Quản lý chủ đề).
- Trong ứng dụng Shopify, chạm vào Cửa hàng.
- Trong phần Sales channels (Kênh bán hàng), nhấn vào Cửa hàng trực tuyến.
- Nhấn vào Manage themes (Quản lý chủ đề).
Tìm chủ đề bạn muốn chỉnh sửa rồi nhấp vào Thao tác > Chỉnh sửa nội dung chủ đề mặc định.
Trong hộp Lọc, bắt đầu nhập
unavailable
để hiển thị bản dịch của từ "Unavailable".Thay thế từ Unavailable thành
Make a selection
.Nhấp vào Save (Lưu).
Các bước thực hiện dành cho chủ đề Venture
Hãy thực hiện theo các bước sau để áp dụng nội dung tùy chỉnh cho chủ đề Venture:
Chỉnh sửa tập tin JavaScript của chủ đề
Để chỉnh sửa tệp JavaScript của chủ đề:
Trong trang quản trị Shopify, vào mục Cửa hàng trực tuyến > Chủ đề.
Tìm chủ đề bạn muốn chỉnh sửa, nhấp vào nút ... để mở menu thao tác, sau đó nhấp vào Chỉnh sửa mã.
Trong ứng dụng Shopify, chạm vào Cửa hàng.
Trong phần Kênh bán hàng, chạm vào Cửa hàng trực tuyến.
Chạm vào Manage themes (Quản lý chủ đề).
Tìm chủ đề bạn muốn chỉnh sửa, nhấp vào nút ... để mở menu thao tác, sau đó nhấp vào Chỉnh sửa mã.
Trong ứng dụng Shopify, chạm vào Cửa hàng.
Trong phần Kênh bán hàng, chạm vào Cửa hàng trực tuyến.
Chạm vào Manage themes (Quản lý chủ đề).
Tìm chủ đề bạn muốn chỉnh sửa, nhấp vào nút ... để mở menu thao tác, sau đó nhấp vào Chỉnh sửa mã.
Trong thư mục Assets, nhấp vào
theme.js
hoặctheme.js.liquid
.Thêm mã sau vào cuối tệp:
(function() {
if (typeof(productOptions) != "undefined") {
for (i = 0; i < productOptions.length; i++) {
const vowels = ['a', 'e', 'i', 'o', 'u'];
const firstOptionLetter = productOptions[i][i][0].toLowerCase();
let indef = 'a';
if (vowels.includes(firstOptionLetter)) {
indef = 'an';
};
const select = document.querySelectorAll('.single-option-selector')[i];
const options = select.querySelectorAll('option');
if (options.length > 1) {
let option = new Option('Pick ' + indef + ' ' + productOptions[i][i], '');
select.add(option, select.firstChild);
select.selectedIndex = 0;
}
}
}
})();
- Tìm mã sau:
this.currentVariant = this._getVariantFromOptions();
Replace it with:
this.currentVariant = this._getVariantFromOptions() || {};
-
Tìm mã
_updatePrice: function(variant)
. Thay mã sau:
if (
variant.price === this.currentVariant.price &&
variant.compare_at_price === this.currentVariant.compare_at_price
) {
return;
}
with:
/* if (
variant.price === this.currentVariant.price &&
variant.compare_at_price === this.currentVariant.compare_at_price
) {
return;
} */
- Nhấp vào Save (Lưu).
Sửa mẫu trang sản phẩm
Cách chỉnh sửa mẫu trang sản phẩm:
Trong thư mục Sections, chạm vào
product-template.liquid
.Tìm mã sau:
{% assign current_variant = product.selected_or_first_available_variant %}
Replace it with:
{% if product.variants.size > 1 %}
{% assign current_variant = product.selected_variant %}
{% else %}
{% assign current_variant = product.first_available_variant %}
{% endif %}
- Tìm và xóa mã sau:
{% if variant == product.selected_or_first_available_variant %} selected="selected" {% endif %}
If you can't find the code above, then find this code and delete it:
{% if variant == current_variant %} selected="selected" {% endif %}
- Tìm tất cả các lần xuất hiện của mã sau:
{% unless current_variant.available %}
Replace it with:
{% unless current_variant.available or product.variants.size == 1 and variant.available %}
- Tìm mã sau:
{% unless current_variant.available or product.variants.size == 1 and variant.available %}
{{ 'products.product.sold_out' | t }}
{% else %}
{{ 'products.product.add_to_cart' | t }}
{% endunless %}
Replace it with:
{% if current_variant == blank %}
{{ 'products.product.unavailable' | t }}
{% else %}
{% unless current_variant.available or product.variants.size == 1 and variant.available %}
{{ 'products.product.sold_out' | t }}
{% else %}
{{ 'products.product.add_to_cart' | t }}
{% endunless %}
{% endif %}
-
Tìm mã
{% schema %}
. Dán mã sau vào chính dòng của nó ở phía trên:
{% if current_variant == blank %}
<script>
var productOptions = []; {% for option in product.options -%}
var optionObj = {};
optionObj[{{ forloop.index0 }}] = "{{ product.options[forloop.index0] }}";
productOptions.push(optionObj);
{%- endfor %}
</script>
{% endif %}
It should look something like this:
{% if current_variant == blank %}
<script>
var productOptions = []; {% for option in product.options -%}
var optionObj = {};
optionObj[{{ forloop.index0 }}] = "{{ product.options[forloop.index0] }}";
productOptions.push(optionObj);
{%- endfor %}
</script>
{% endif %}
{% schema %}
- Nhấp vào Save (Lưu).
Thay đổi cài đặt ngôn ngữ cho nút Thêm vào giỏ hàng
Bạn có thể thay đổi cài đặt ngôn ngữ cho nút Thêm vào giỏ hàng để các sản phẩm không hiển thị là "Không có" trước khi thao tác lựa chọn được thực hiện.
- Trong phần Shopify admin (Quản trị viên Shopify), vào mục Cửa hàng trực tuyến > Chủ đề.
- Trong ứng dụng Shopify, chạm vào Cửa hàng.
- Trong phần Sales channels (Kênh bán hàng), nhấn vào Cửa hàng trực tuyến.
- Nhấn vào Manage themes (Quản lý chủ đề).
- Trong ứng dụng Shopify, chạm vào Cửa hàng.
- Trong phần Sales channels (Kênh bán hàng), nhấn vào Cửa hàng trực tuyến.
- Nhấn vào Manage themes (Quản lý chủ đề).
Tìm chủ đề bạn muốn chỉnh sửa rồi nhấp vào Thao tác > Chỉnh sửa nội dung chủ đề mặc định.
Trong hộp Lọc, bắt đầu nhập
unavailable
để hiển thị bản dịch của từ "Unavailable".Thay thế từ Unavailable thành
Make a selection
.Nhấp vào Save (Lưu).
Thêm lời nhắc vào menu thả xuống mẫu mã
Để thêm lời nhắc vào menu thả xuống mẫu mã:
Trong thư mục Đoạn mã, nhấp vào Thêm đoạn mã mới.
Đặt tên cho đoạn mã mới
pick-an-option
.Trong tập tin của đoạn mã mới, dán mã lưu trữ trên GitHub.
Nhấp vào Save (Lưu).
Trong thư mục Layout, nhấp vào
theme.liquid
.Tìm thẻ có kết thúc là
</body>
ở gần phía dưới cùng của tập tin. Trên dòng mới nằm ngay phía trên thẻ có kết thúc là</body>
, dán vào mã sau:
{% render 'pick-an-option' %}

Nhấp vào Save (Lưu).
Tìm tập tin chứa biểu mẫu "add to cart" (thêm vào giỏ hàng). Tập tin này sẽ có thuộc tính
action
được đặt thành/cart/add
.Tìm mã sau trong biểu mẫu:
<option {% if variant == product.selected_or_first_available_variant %} selected="selected" {% endif %} data-sku="{{ variant.sku }}" value="{{ variant.id }}">{{ variant.title }} - {{ variant.price | money_with_currency }}</option>
or
<option {% if variant == current_variant %} selected="selected" {% endif %} data-sku="{{ variant.sku }}" value="{{ variant.id }}">{{ variant.title }} - {{ variant.price | money_with_currency }}</option>
Replace it with:
<option {% if forloop.length <= 1 and variant == product.selected_or_first_available_variant %} selected="selected" {% endif %} data-sku="{{ variant.sku }}" value="{{ variant.id }}">{{ variant.title }} - {{ variant.price | money_with_currency }}</option>
- Tìm và thay thế mã sau:
{% assign featured_image = product.selected_or_first_available_variant.featured_image | default: product.featured_image %}
Replace with:
{% assign featured_image = product.selected_variant.featured_image | default: product.featured_image %}
### Other free Shopify themesIf you use any other Shopify theme, then find this code:
{% assign current_variant = product.selected_or_first_available_variant %}
Replace it with:
{% assign current_variant = product.selected_variant %}
- Nhấp vào Save (Lưu).
Thay đổi cài đặt ngôn ngữ cho nút Thêm vào giỏ hàng
Bạn có thể thay đổi cài đặt ngôn ngữ cho nút Thêm vào giỏ hàng để các sản phẩm không hiển thị là "Không có" trước khi thao tác lựa chọn được thực hiện.
- Trong phần Shopify admin (Quản trị viên Shopify), vào mục Cửa hàng trực tuyến > Chủ đề.
- Trong ứng dụng Shopify, chạm vào Cửa hàng.
- Trong phần Sales channels (Kênh bán hàng), nhấn vào Cửa hàng trực tuyến.
- Nhấn vào Manage themes (Quản lý chủ đề).
- Trong ứng dụng Shopify, chạm vào Cửa hàng.
- Trong phần Sales channels (Kênh bán hàng), nhấn vào Cửa hàng trực tuyến.
- Nhấn vào Manage themes (Quản lý chủ đề).
Tìm chủ đề bạn muốn chỉnh sửa rồi nhấp vào Thao tác > Chỉnh sửa nội dung chủ đề mặc định.
Trong hộp Lọc, bắt đầu nhập
unavailable
để hiển thị bản dịch của từ "Unavailable".Thay thế từ Unavailable thành
Make a selection
.Nhấp vào Save (Lưu).