You need to enable JavaScript to run this app.
优惠活动
大模型
产品
解决方案
定价
更多

使用Gutenberg作为编辑器时无法访问WooCommerce产品评论怎么办

问题根因

WooCommerce的产品评价属于自定义评论类型,内置了评分、已验证购买标记等专属元字段与配套脚本依赖。手动为product自定义文章类型启用古腾堡编辑器、禁用Woo区块时,很容易误移除产品评价的依赖脚本,同时古腾堡默认的评论模块无法兼容产品评价的自定义结构,最终导致评论模块无法正常使用。

解决方法

方法1:强制恢复产品编辑页的适配版评论元盒(最稳妥)

将以下代码添加到主题的functions.php文件或自定义代码片段插件中,即可替换古腾堡默认评论模块,加载兼容WooCommerce产品评价的经典元盒:

// 恢复产品编辑页的WooCommerce适配评论元盒
add_action( 'add_meta_boxes', 'restore_product_review_metabox', 99 );
function restore_product_review_metabox() {
    // 移除古腾堡默认的不兼容评论元盒
    remove_meta_box( 'commentsdiv', 'product', 'normal' );
    // 加载适配产品评价的经典元盒
    add_meta_box( 
        'woocommerce-commentsdiv', 
        __( '产品评价', 'woocommerce' ), 
        'post_comment_meta_box', 
        'product', 
        'normal', 
        'high', 
        array( '__back_compat_meta_box' => true ) 
    );
}

// 确保产品类型开启评论与自定义字段支持
add_filter( 'register_post_type_args', 'enable_product_comment_support', 10, 2 );
function enable_product_comment_support( $args, $post_type ) {
    if ( 'product' === $post_type ) {
        $args['supports'] = array_unique( array_merge( $args['supports'], [ 'comments', 'custom-fields' ] ) );
    }
    return $args;
}

方法2:修正Woo区块禁用逻辑

检查你之前禁用产品编辑页Woo区块的代码,不要卸载评价相关的依赖脚本:

  • 保留wc-reviews、wc-admin-product-reviews相关的脚本与样式加载,不要将其加入禁用队列
  • 仅禁用不需要的前端块编辑脚本即可,示例的正确禁用逻辑参考:
add_action( 'admin_enqueue_scripts', 'disable_unnecessary_woo_blocks_on_product_edit', 999 );
function disable_unnecessary_woo_blocks_on_product_edit() {
    $screen = get_current_screen();
    if ( $screen->id === 'product' ) {
        // 仅禁用不需要的商品区块脚本,不涉及评价相关依赖
        wp_dequeue_script( 'wc-blocks-product-editor' );
        wp_dequeue_script( 'wc-all-blocks' );
    }
}

临时替代方案

如果不需要在产品编辑页管理评价,可直接进入后台「评论」菜单,顶部筛选条件选择产品评价,即可批量管理所有商品的用户评价。

内容的提问来源于stack exchange,提问作者D_P

相关产品推荐
方舟 Agent Plan

超全模态模型 × Harness 升级,最新支持 Deepseek-V4.1-Flash、GLM-5.3 系列、Doubao-Seedream-5.0-pro、Kimi-K3 (部分), 限时 9.9 元起

最近更新时间:2026.09.29 18:15:03