要解决根据 Shopify 中的颜色选择更改描述的问题,请确保 HTML 中的变体 ID 与您的 Shopify 产品变体的 ID 相匹配。这是对您的脚本的简要调整:
<script type="text/javascript">
$(document).ready(function() {
// Function to change description visibility based on variant selection
var selectCallback = function(variant, selector) {
$('.description').hide(); // Hide all descriptions
if (variant) {
$('#' + variant.id).show(); // Show the description for the selected variant
}
};
// Attach the function to variant selection changes
$('select[name=id]').change(function() {
var variantId = $(this).val();
var variant = { id: variantId };
selectCallback(variant);
});
});
</script>
此脚本应根据 Shopify 中所选的变体正确处理显示和隐藏描述。