Woocommerceでレーティングのカスタム項目を追加しましたが、各項目のアベレージを取得したいです。
標準のアベレージ表示は
php
1$rating_count = $product->get_rating_count(); 2$average = $product->get_average_rating(); 3 4<?php echo wc_get_rating_html( $average, $rating_count ); ?>
で表示されています。
$averageにカスタム項目のレーティングを投げたいのですが、
get_average_rating()を見てみますと
php
1public function get_average_rating( $context = 'view' ) { 2 return $this->get_prop( 'average_rating', $context ); 3 }
get_propは
php
1protected function get_prop( $prop, $context = 'view' ) { 2 $value = null; 3 4 if ( array_key_exists( $prop, $this->data ) ) { 5 $value = array_key_exists( $prop, $this->changes ) ? $this->changes[ $prop ] : $this->data[ $prop ]; 6 7 if ( 'view' === $context ) { 8 $value = apply_filters( $this->get_hook_prefix() . $prop, $value, $this ); 9 } 10 } 11 12 return $value; 13 }
となっています。
これら標準の関数を再利用できないか検討しています。
どうやってアベレージを計算しているか読み解けず、行き詰まってしまいました。
ちなみに各カスタム項目のレーティングはcomment_metaにrating1〜5で格納してあり、個別に表示する際は、echo wc_get_rating_htmlにmetaを渡してます。
よろしくおねがいします。
あなたの回答
tips
プレビュー