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>
購入履歴に閲覧中の商品が存在しない場合、レビュー投稿のボタンが非表示になります。
ご参考になりましたら幸いです。
2月に、新しい英語版AMAディスカッションボードで2週間にわたって初めてのコミュニティAMAを開催しました。
By SarahF_Shopify Mar 19, 2023不正注文やチャージバック被害はビジネスへ大きな被害を与えます、このブログでは簡単な防止策を紹介し、ストア保護を最適化します
By Mirai Mar 13, 2023Eコマースの自動化に関して大きな告知がございます。2022年3月22日より、Shopify FlowをAdvanced(プレミアム)プランの全てのご利用者様に提供を開始しました。...
By Nanami Feb 17, 2023