Advertisement
geminilabs

[site-reviews] remove empty custom ratings from the reviews

Jul 13th, 2021
1,882
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
  1. /**
  2.  * Removes empty custom rating tags.
  3.  * @param array $tags
  4.  * @param \GeminiLabs\SiteReviews\Review $review
  5.  * @param \GeminiLabs\SiteReviews\Modules\Html\ReviewHtml $reviewHtml
  6.  * @return array
  7.  */
  8. add_filter('site-reviews/review/build/after', function ($tags, $review, $reviewHtml) {
  9.     // Change this array to include your custom rating field names
  10.     // The array key is the field name
  11.     // The array value is the field template tag
  12.     $customRatings = [
  13.         'sound_rating' => 'sound_rating',
  14.         'noise_rating' => 'the_noise_rating',
  15.     ];
  16.     foreach ($review->custom as $key => $value) {
  17.         if (array_key_exists($key, $customRatings) && empty($value)) {
  18.             $tags[$customRatings[$key]] = '';
  19.         }
  20.     }
  21.     return $tags;
  22. }, 15, 3);
Advertisement
Advertisement
Advertisement
RAW Paste Data Copied
Advertisement