Liquid、JavaScriptなどに関する質問
product reviews にてレビュー機能を実装しています。
購入者のみレビューを記入できる様にしたいのですが、どうすればいいのでしょうか?
よろしくお願いいたします。
解決済! ベストソリューションを見る。
成功
現状product reviewsにそのような機能は実装されていないようですが、JavaScriptで無理やり実現してみました。
以下のコードをproduct reviewsのタグを挿入しているファイル(例としてDebutテーマのproduct-template.liquid)の先頭に追加後、保存をお願いします。
※正攻法ではない為product reviewsの仕様が変わった場合などに動作しなくなる可能性があります
<script>
document.addEventListener('DOMContentLoaded', function() {
const config = {
childList : true
};
const target = document.getElementById('shopify-product-reviews')
const observer = new MutationObserver(records => {
observer.disconnect();
let actions = document.getElementsByClassName('spr-summary-actions');
{% assign match = false %}
{% for order in customer.orders %}
{% for line_item in order.line_items %}
{% if line_item.product_id == product.id %}
{% assign match = true %}
{% break %}
{% endif %}
{% endfor %}
{% if match %}
{% break %}
{% endif %}
{% endfor %}
{% if match == false %}
actions[0].innerHTML = '';
{% endif %}
observer.observe(target, config);
})
observer.observe(target, config)
});
</script>
購入履歴に閲覧中の商品が存在しない場合、レビュー投稿のボタンが非表示になります。
ご参考になりましたら幸いです。
成功
現状product reviewsにそのような機能は実装されていないようですが、JavaScriptで無理やり実現してみました。
以下のコードをproduct reviewsのタグを挿入しているファイル(例としてDebutテーマのproduct-template.liquid)の先頭に追加後、保存をお願いします。
※正攻法ではない為product reviewsの仕様が変わった場合などに動作しなくなる可能性があります
<script>
document.addEventListener('DOMContentLoaded', function() {
const config = {
childList : true
};
const target = document.getElementById('shopify-product-reviews')
const observer = new MutationObserver(records => {
observer.disconnect();
let actions = document.getElementsByClassName('spr-summary-actions');
{% assign match = false %}
{% for order in customer.orders %}
{% for line_item in order.line_items %}
{% if line_item.product_id == product.id %}
{% assign match = true %}
{% break %}
{% endif %}
{% endfor %}
{% if match %}
{% break %}
{% endif %}
{% endfor %}
{% if match == false %}
actions[0].innerHTML = '';
{% endif %}
observer.observe(target, config);
})
observer.observe(target, config)
});
</script>
購入履歴に閲覧中の商品が存在しない場合、レビュー投稿のボタンが非表示になります。
ご参考になりましたら幸いです。
ありがとうございます!
助かりました!
とても感謝しています!
構築を進めていきます!
Shopify アカデミーの学習パスと認定スキルバッジExpanding Your Shopify Business Internationallyを活用して、国際的にビジネ...
By Shopify Feb 7, 2025Shopify アカデミーの学習パスB2B on Shopify:立ち上げとカスタマイズで卸売販売に進出しましょう。これら3つの無料コースは、ShopifyストアでB2B機能...
By Shopify Jan 31, 2025サポートの選択肢が増えていく中、最適となる選択の判断が難しくなっているかと存じます。今回は問題の解決に最適となるサポートの選択方法を、紹介させて頂きます。 選択肢のご紹介...
By Mirai Oct 6, 2024