Skip to content

Instantly share code, notes, and snippets.

@khoipro
Last active June 6, 2024 05:20
Show Gist options
  • Save khoipro/ff333bf24a274bbdf1d18144ef946220 to your computer and use it in GitHub Desktop.
Save khoipro/ff333bf24a274bbdf1d18144ef946220 to your computer and use it in GitHub Desktop.
Display product tabs reviews with count
<?php
/**
* Override WooCommerce Hooks
*
* @package woocommerce-extends
* @author Khoi Pro <khoi@chuyendev.com>
* @since 0.0.1
**/
add_filter('woocommerce_product_tabs', 'chuyendev_woocommerce_product_tabs');
/**
* Override product tabs review title to display a correct count
*
**/
function chuyendev_woocommerce_product_tabs( $tabs ) {
$comments = get_comment_count( get_the_ID() );
if ( $comments['approved'] > 0 ) {
$tabs['reviews']['title'] = sprintf( '%s (%d)', __('Reviews', 'woocommerce'), absint( $comments['approved'] ) );
} else {
$tabs['reviews']['title'] = __('Reviews', 'woocommerce');
}
return $tabs;
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment