WP SITES

3085 Coded Tutorials & 287 Plugins

If No Reviews Change Reviews Tab Title

This code enables you to change your reviews tab from Reviews ( 0 ) to something else based on the number of reviews published.

add_filter( 'woocommerce_product_reviews_tab_title', 'wpsitesdotnet_woocommerce_reviews_tab_title' );
function wpsitesdotnet_woocommerce_reviews_tab_title( $title ) {

    global $product;
    
    $count = $product->get_review_count();
    
    if ( $count === 0 ) {
    
        return __( 'Leave a Review', 'woocommerce' );
        
    }
    
    return sprintf( __( 'Reviews (%d)', 'woocommerce' ), $count );
    
}

In this case, if reviews count is 0, the title is modified from Reviews ( 0 ) to Leave a Review.

Paste the code into your child themes functions file or PHP code snippets plugin.

Or, you can copy over the WooCommerce single-product-reviews.php file to your-child-theme/woocommerce/single-product-reviews.php and modify it there but you’ll need to update the file when WooCommerce does otherwise you’ll get notices in the backend when you are logged in.

The code is tested and works.

Leave a Reply

New Plugins