• Resolved Trinaa3

    (@orenlebbo)


    Hi,

    There’s an error message in the comments/reviews section: Fatal error: Uncaught Error:

    Call to a member function get_rating_counts() on null in /home/cannabiz/public_html/wp-content/themes/listify/functions.php:807 Stack trace: #0 /home/cannabiz/public_html/wp-includes/class-wp-hook.php(288): loop_product_get_rating_html(‘<div class=”sta…’, ‘5’, 0) #1 /home/cannabiz/public_html/wp-includes/plugin.php(206): WP_Hook->apply_filters(‘<div class=”sta…’, Array) #2 /home/cannabiz/public_html/wp-content/plugins/woocommerce/includes/wc-template-functions.php(3435): apply_filters(‘woocommerce_pro…’, ‘<div class=”sta…’, ‘5’, 0) #3 /home/cannabiz/public_html/wp-content/plugins/woo-photo-reviews/admin/admin.php(1698): wc_get_rating_html(‘5’) #4 /home/cannabiz/public_html/wp-includes/class-wp-hook.php(288): VI_WOO_PHOTO_REVIEWS_Admin_Admin->column_callback(‘wcpr_rating’, ‘309’) #5 /home/cannabiz/public_html/wp-includes/class-wp-hook.php(312): WP_Hook->apply_filters(”, Array) #6 /home/cannabiz/public_html/wp-includes/plugin.php(478): WP_Hook->do_action(Array) #7 /home/cannabiz/public_ in /home/cannabiz/public_html/wp-content/themes/listify/functions.php on line 807

    Screenshot here: https://www.dropbox.com/s/eq9tx3gijxezp66/Screenshot%202020-02-01%2016.44.19.png?dl=0

    Thanks

Viewing 12 replies - 1 through 12 (of 12 total)
  • Hi,
    What is the code on line 807 in wp-content/themes/listify/functions.php ?

    Thread Starter Trinaa3

    (@orenlebbo)

    (803)add_filter( ‘woocommerce_product_get_rating_html’, ‘loop_product_get_rating_html’, 20, 3 );
    (804)function loop_product_get_rating_html( $html, $rating, $count ){
    (805) if ( 0 < $rating && ! is_product() ) {
    (806) global $product;
    (807) $rating_cnt = array_sum($product->get_rating_counts());
    (808) $count_html = ‘ <div class=”count-rating”>’ . $rating_cnt .'</div>’;
    (809)
    (810) $html = ‘<div class=”container-rating”><div class=”star-rating”>’;
    (811) $html .= wc_get_star_rating_html( $rating, $count );
    (812) $html .= ‘</div>’ . $count_html . ‘</div>’;
    (813) }
    (814) return $html;
    (815)}

    • This reply was modified 4 years, 4 months ago by Trinaa3.

    This function causes the error.
    Please replace this line:
    if ( 0 < $rating && ! is_product() ) {
    with this:
    if ( !is_admin() && 0 < $rating && ! is_product() ) {
    Best regards

    Or you’d better check $product before using it:

    add_filter( 'woocommerce_product_get_rating_html', 'loop_product_get_rating_html', 20, 3 );
    function loop_product_get_rating_html( $html, $rating, $count ) {
    	if ( 0 < $rating && ! is_product() ) {
    		global $product;
    		if ( $product ) {
    			$rating_cnt = array_sum( $product->get_rating_counts() );
    			$count_html = '<div class=”count-rating”>' . $rating_cnt . '</div>';
    
    			$html = '<div class=”container-rating”><div class=”star-rating”>';
    			$html .= wc_get_star_rating_html( $rating, $count );
    			$html .= '</div>' . $count_html . '</div>';
    		}
    	}
    
    	return $html;
    }
    Thread Starter Trinaa3

    (@orenlebbo)

    Sorry, which ones to use?
    Replace the first and add the second?

    Just replace your code(line 803 to 815) with the second code i gave.

    Thread Starter Trinaa3

    (@orenlebbo)

    Amazing.
    Thank you so much!

    You’re welcome 🙂

    Thread Starter Trinaa3

    (@orenlebbo)

    Hi again,

    1. Seems like it caused another error, on “wp-includes”,
    see: https://i.ibb.co/PDkc5MN/84312107-163676845054269-3490721780627144704-n.png

    2. It changed the looks of the ratings on products. Instead of showing stars it shows text and numbers. see: https://cannabiz.co.il/shop/

    Thanks 🙂

    • This reply was modified 4 years, 4 months ago by Trinaa3.

    Hi,
    Please try deactivating our plugin and restore your code above to see if all these issues are gone.

    Thread Starter Trinaa3

    (@orenlebbo)

    So – you tell me not to use this plugin at all?

    No,
    I tell you to try it so that we can find which causes these issues. That’s how we debug error.

Viewing 12 replies - 1 through 12 (of 12 total)
  • The topic ‘Error message in dashboard’ is closed to new replies.