【发布时间】:2021-10-11 06:55:43
【问题描述】:
我想在产品存档页面的类别中添加一个自定义类,以便我可以将自定义样式添加到类别标签中。
例子:
-
类别 1 中的产品 X --> 黄色类别标签
-
类别 2 中的产品 Y --> 红色类别标签
我正在使用这个 php sn-p,但这是针对单个产品页面并应用于 <body> 元素。如何将其更改为也适用于商店存档页面?
add_filter( 'body_class','my_body_classes2' );
function my_body_classes2( $classes ) {
if ( is_product() ) {
global $post;
$terms = get_the_terms( $post->ID, 'product_cat' );
foreach ($terms as $term) {
$product_cat_id = $term->term_id;
$classes[] = 'product-in-cat-' . $product_cat_id;
}
}
return $classes;
}
【问题讨论】:
标签: wordpress woocommerce product