如何添加单品标签作为正文class?

How to add single product tag as body class?

我看过很多关于如何根据 WooCommerce 类别添加正文标签的参考资料,但我想要实现的是从产品标签添加正文 类。

有什么指点吗?

像这样的东西应该可以工作

function woo_body_classes($classes) {
    if(is_product_category()):
        global $wp_query;
        $current_products = wp_list_pluck( $wp_query->posts, 'ID' );
        $tags_list = array();
        foreach($current_products as $product):
            $tags = get_the_terms($product,'product_tag');
            if ( ! empty( $tags ) && ! is_wp_error( $tags ) ):
                foreach($tags as $tag):
                    $tags_list[] = $tag->name;
                endforeach;
            endif;
        endforeach;
        $tags_list = array_unique($tags_list);
        $classes[] = implode(' ',$tags_list);
    endif;
    return $classes;
}
add_filter( 'body_class','woo_body_classes' );