Display Stars for Rating Fields

Code

Filename: gpeb-display-stars-for-rating-fields.php

<?php
/**
 * Gravity Perks // Entry Blocks // Display Stars for Rating Fields
 * https://gravitywiz.com/documentation/gravity-forms-entry-blocks/
 */
add_filter( 'gpeb_entry', function( $entry, $form ) {
	foreach ( $form['fields'] as $field ) {
		if ( $field->get_input_type() === 'rating' ) {
			$selected_value = $entry[ $field->id ];
			foreach ( $field->choices as $index => $choice ) {
				if ( $choice['value'] === $selected_value ) {
					$entry[ $field->id ] = str_repeat( '⭐', $index + 1 );
					break 2;
				}
			}
		}
	}
	return $entry;
}, 10, 2 );

Leave a Reply

Your email address will not be published. Required fields are marked *

  • Trouble installing this snippet? See our troubleshooting tips.
  • Need to include code? Create a gist and link to it in your comment.
  • Reporting a bug? Provide a URL where this issue can be recreated.

By commenting, I understand that I may receive emails related to Gravity Wiz and can unsubscribe at any time.