Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Removing the (0) on the WooCommerce Reviews Tab

I've succeeding in removing the (0) on the Reviews tab heading when there is no reviews. In marketing - it's probably best practice to not show that a product has 0 reviews. Here is the code that I have placed in my child theme's functions.php file which is found in the WooCommerce plugin file wc-template-function.php:

if ( ! function_exists( 'woocommerce_default_product_tabs' ) ) {

/**
 * Add default product tabs to product pages.
 *
 * @param array $tabs
 * @return array
 */
function woocommerce_default_product_tabs( $tabs = array() ) {
    global $product, $post;

    // Description tab - shows product content
    if ( $post->post_content ) {
        $tabs['description'] = array(
            'title'    => __( 'Description', 'woocommerce' ),
            'priority' => 10,
            'callback' => 'woocommerce_product_description_tab'
        );
    }

    // Additional information tab - shows attributes
    if ( $product && ( $product->has_attributes() || ( $product->enable_dimensions_display() && ( $product->has_dimensions() || $product->has_weight() ) ) ) ) {
        $tabs['additional_information'] = array(
            'title'    => __( 'Additional Information', 'woocommerce' ),
            'priority' => 20,
            'callback' => 'woocommerce_product_additional_information_tab'
        );
}

    // Reviews tab - shows comments
    if ( comments_open() ) {
    $check_product_review_count = $product->get_review_count();
    if ( $check_product_review_count == 0 ) {
        $tabs['reviews'] = array(
            'title'    => sprintf( __( 'Reviews', 'woocommerce' ) ),
            'priority' => 30,
            'callback' => 'comments_template'
        );
        }
        else {
        $tabs['reviews'] = array(
            'title'    => sprintf( __( 'Reviews (%d)', 'woocommerce', $product->get_review_count() ), $product->get_review_count() ),
            'priority' => 30,
            'callback' => 'comments_template'
        );
        }
    }

    return $tabs;
}
} 

My question is - is this the most efficient way of modifying this without changing the core files of woocommerce? The function "woocommerce_default_product_tabs" is a pluggable function, but it seems like I could somehow use a filter instead of copying this entire function into my child theme and editing it from there. I just need to get at this line of code:

title'    => sprintf( __( 'Reviews (%d)', 'woocommerce', $product->get_review_count() ),

And add an if statement to check if there is no comments to change this above line like in the line above:

title'    => sprintf( __( 'Reviews', 'woocommerce' ),
like image 744
Shinosky Avatar asked Nov 02 '15 21:11

Shinosky


People also ask

How do I remove the Review tab in WooCommerce?

Disable Reviews in the Settings Go to WooCommerce > Settings > Products and uncheck Enable product reviews .

How do I fix WooCommerce product Review tab not showing on product page?

In the admin area of your store, click on WooCommerce and then Settings. Next, go to settings for products by clicking on Products tab and then choosing General tab. Scroll down to Reviews area where you will see settings for showing product reviews. Make sure that reviews are enabled.

How do I change the product tab in WooCommerce?

To create Saved Tabs, go to Settings > Custom Product Tabs for WooCommerce. Click on the Add New button to create a new Saved Tab. Enter a title and fill the content for this new Saved Tab. Then click on the Save Tab button.


1 Answers

It's pretty easy. You can change the title of any tabs:

add_filter( 'woocommerce_product_tabs', 'wp_woo_rename_reviews_tab', 98);
function wp_woo_rename_reviews_tab($tabs) {
    global $product;
    $check_product_review_count = $product->get_review_count();
    if ( $check_product_review_count == 0 ) {
        $tabs['reviews']['title'] = 'Reviews';
    } else {
        $tabs['reviews']['title'] = 'Reviews('.$check_product_review_count.')';
    }
    return $tabs;
}

like image 137
Alex Avatar answered Sep 24 '22 23:09

Alex