前提・実現したいこと
Wordpressのwoocommerceのカスタマイズをしています。
レビューのスター項目を増やそうと拡張しています。
レビュー項目の増設と保存はできたのですが、表示する段階で下記のような症状がありました。
ソースコード
lang
1function hoge_woocommerce_review_display_rating() { 2 if ( post_type_supports( 'product', 'comments' ) ) { 3 if ( ! defined( 'ABSPATH' ) ) { 4 exit; // Exit if accessed directly 5 } 6 global $comment; 7 $rating = intval( get_comment_meta( $comment->comment_ID, 'rating2', true ) ); 8 //↑これを$rating2とすると、以下3〜5も表示されなくなります。 9 $rating3 = intval( get_comment_meta( $comment->comment_ID, 'rating3', true ) ); 10 $rating4 = intval( get_comment_meta( $comment->comment_ID, 'rating4', true ) ); 11 $rating5 = intval( get_comment_meta( $comment->comment_ID, 'rating5', true ) ); 12 13 if ( $rating && 'yes' === get_option( 'woocommerce_enable_review_rating' ) ) { 14 echo hoge_wc_get_rating_html2( $rating ); 15 echo hoge_wc_get_rating_html3( $rating3 ); 16 echo hoge_wc_get_rating_html4( $rating4 ); 17 echo hoge_wc_get_rating_html5( $rating5 ); 18 } 19 } 20} 21add_action( 'moge_woocommerce_review_before_comment_meta', 'hoge_woocommerce_review_display_rating', 10 ); 22 23
発生している問題・エラーメッセージ
function.phpに記述しています。 変数$ratingを$rating2とすると、標準のスター(1項目)のみの表示となってしまいます。
試したこと
$ratingさえあればなぜか機能します。
補足情報(FW/ツールのバージョンなど)
wordpress4.9.7
woocommerce3.4.3を使用しています。
hoge_wc_get_rating_html2〜5はそれぞれクラス名を変えたりしており、基本的な内容は一緒です。
ここは配列で解決できそうですが…。
よろしくお願いします。
回答1件
あなたの回答
tips
プレビュー