如果为空,请删除 Woocommerce 评论选项卡 [英] Remove Woocommerce review tab if empty

查看:23
本文介绍了如果为空,请删除 Woocommerce 评论选项卡的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

如何为仅没有评论的产品隐藏评论"选项卡?我找到了这个代码:

How can I hide the Review tab for products without reviews only? I've found this code:

add_filter( 'woocommerce_product_tabs', 'delete_tab', 98 );函数 delete_tab( $tabs ) {取消设置($tabs['评论']);返回 $tabs;}

但它删除了所有地方的评论,即使是在有一些评论的产品中也是如此.

But it removes the Reviews everywhere, even in products that do have some reviews.

推荐答案

检查:

add_filter( 'woocommerce_product_tabs', 'delete_tab', 98 );
function delete_tab( $tabs ) {

    global $product;
    $id = $product->id;

    $args = array ('post_type' => 'product', 'post_id' => $id);    
    $comments = get_comments( $args );

    if(empty($comments)) {
        unset( $tabs['reviews'] );
    }

    return $tabs;
}

这篇关于如果为空,请删除 Woocommerce 评论选项卡的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆