Skip to content

Instantly share code, notes, and snippets.

Show Gist options
  • Save saifsultanc/43049c840dad43eb71479aba18fd2a99 to your computer and use it in GitHub Desktop.
Save saifsultanc/43049c840dad43eb71479aba18fd2a99 to your computer and use it in GitHub Desktop.
gpeb-display-svg-star-icon-for-rating-fields.php
<?php
add_filter( 'gpeb_entry', function( $entry, $form ) {
$svg_star_icon = '<svg xmlns="http://www.w3.org/2000/svg" width="12" height="12" fill="none"><g clip-path="url(#a)"><path fill="url(#b)" d="M11.358 4.08 8.12 3.607 6.675.675a.78.78 0 0 0-1.35 0L3.879 3.609l-3.237.47a.75.75 0 0 0-.417 1.28l2.342 2.284-.553 3.224a.75.75 0 0 0 1.088.791L6 10.135l2.895 1.521a.75.75 0 0 0 1.089-.79L9.43 7.641l2.344-2.282a.75.75 0 0 0-.416-1.279h-.001Z"/></g><defs><linearGradient id="b" x1="9.043" x2="8.9" y1="11.165" y2=".684" gradientUnits="userSpaceOnUse"><stop stop-color="#E1A905"/><stop offset="1" stop-color="#F8E193"/></linearGradient><clipPath id="a"><path fill="#fff" d="M0 0h12v12H0z"/></clipPath></defs></svg>';
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( $svg_star_icon, $index + 1 );
break 2;
}
}
}
}
return $entry;
}, 10, 2 );
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment