特定产品类别的 Woocommerce 自定义样式?

Woocommerce custom style for specific product category?

有没有简单的方法可以在 Woocommerce 中为特定产品添加自定义样式?例如,我希望类别为 'Category1' 的所有产品的页面背景颜色为蓝色,类别为 'Category2' 的所有产品的页面背景颜色为白色。

不幸的是,我对PHP一无所知。你能像我是一名五年级学生一样向我解释解决方案吗?

提前致谢:)

您需要在主题的 functions.php 文件中添加一个功能:

// add taxonomy term to body_class
function woo_custom_taxonomy_in_body_class( $classes ){
  if( is_singular( 'product' ) )
  {
    $custom_terms = get_the_terms(0, 'product_cat');
    if ($custom_terms) {
      foreach ($custom_terms as $custom_term) {
        $classes[] = 'product_cat_' . $custom_term->slug;
      }
    }
  }
  return $classes;
}
add_filter( 'body_class', 'woo_custom_taxonomy_in_body_class' );

这个函数是cribbed from here. 此函数会将产品类别 slug 作为 class 名称添加到 <body> 元素,这将允许您专门针对该页面的样式。