I have this code that set reviews tab to show first before item description.
JavaScript
x
add_filter( 'woocommerce_product_tabs', 'woo_reorder_tabs', 98 );
function woo_reorder_tabs( $tabs ) {
$tabs['reviews']['priority'] = 5; // Reviews first
$tabs['description']['priority'] = 10; // Description second
return $tabs;
}
Its works fine, But i want to set it to do it only if the number of reviews high from 0. Something like :
JavaScript
function woo_reorder_tabs( $tabs ) {
if(is_review()){
$tabs['reviews']['priority'] = 5; // Reviews first
$tabs['description']['priority'] = 10; // Description second
return $tabs;
}
}
Is there any hook/ function / filter to get number of product reviews?
Thanks.
Advertisement
Answer
reviews in woocommerce is just comments in wordpress… so using get_comments_number should work.
JavaScript
function woo_reorder_tabs( $tabs ) {
if(get_comments_number() > 0){
$tabs['reviews']['priority'] = 5; // Reviews first
$tabs['description']['priority'] = 10; // Description second
}
return $tabs;
}