How can we help?

If you are looking for support for our PokaTheme, this is the place!

Home Forums PokaTheme support Change Affiliate Rating Scale from 5-point to 11-point

Tagged: 

Viewing 2 posts - 1 through 2 (of 2 total)
  • Author
    Posts
  • #18320
    meow
    Participant

    Hi! Is there a way to change affiliate rating scale from a 5-point scale (1-5 stars) to 11-point scale (0-10 stars)?

    #18323
    admin
    Keymaster

    Hello!

    You could try adding the below code to your child theme’s functions.php:

    // Example filter to alter Poka Metabox Field "Affiliate Rating" (pokafield_affiliate_rating)
    add_filter( 'poka_metabox_field_pokafield_affiliate_rating', 'poka_child_637f2f4047a75' );
    function poka_child_637f2f4047a75( $field ) {
    	// Change the field max to 10
    	$field['max'] = 10;
    	return $field;
    }
    
    function poka_affiliate_rating( $review_id, $atts = array() ) {
    
    	$html         = '';
    	$count        = 0;
    	$rating_num   = poka_affiliate_rating_number( $review_id );
    	$rating_icons = poka_affiliate_rating_icons();
    	$half_icon    = apply_filters( 'poka_affiliate_rating_half_icon', true );
    
    	if ( $rating_num ) {
    
    		if ( in_array( 'rating_num', $atts ) ) {
    			$html .= '<div class="review-rating">';
    			$html .= '<span><strong>' . $rating_num . '</strong>/10</span>';
    		}
    
    		$html .= '<div class="rating">';
    
    		$rest = 10 - $rating_num;
    
    		while ( $count < floor( $rating_num ) ) {
    				$html .= $rating_icons['full_star'];
    				$count++;
    		}
    
    		if ( $rest > 0 ) {
    
    			$count = 0;
    
    			while ( $count < $rest ) {
    
    				$dec = $rating_num - floor( $rating_num );
    
    				if ( $half_icon ) {
    
    					if ( 0.7 > $dec && 0.3 < $dec && is_float( $rest ) && 0 == $count ) {
    						$html .= $rating_icons['half_star'];
    					} elseif ( 0.7 <= $dec && is_float( $rest ) && 0 == $count ) {
    						$html .= $rating_icons['full_star'];
    					} else {
    						$html .= $rating_icons['empty_star'];
    					}
    				} else {
    
    					if ( $dec >= 0.6 && is_float( $rest ) && 0 == $count ) {
    						$html .= $rating_icons['full_star'];
    					} else {
    						$html .= $rating_icons['empty_star'];
    					}
    				}
    
    				$count++;
    			}
    		}
    
    		$html .= '</div>';
    		$html .= '<!--/.rating-->';
    
    		if ( in_array( 'rating_num', $atts ) ) {
    			$html .= '</div>';
    			$html .= '<!--/. review -rating-->';
    		}
    	}
    
    	return apply_filters( 'poka_affiliate_rating_html', $html );
    }
    
    
Viewing 2 posts - 1 through 2 (of 2 total)
  • You must be logged in to reply to this topic.