Last active
June 6, 2024 05:20
-
-
Save khoipro/ff333bf24a274bbdf1d18144ef946220 to your computer and use it in GitHub Desktop.
Display product tabs reviews with count
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
<?php | |
/** | |
* Override WooCommerce Hooks | |
* | |
* @package woocommerce-extends | |
* @author Khoi Pro <[email protected]> | |
* @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