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

问题描述:

有没有一种简单的方法将自定义样式添加到Woocommerce中的特定产品中?例如,我希望所有具有“类别1”类别的产品都具有蓝色背景颜色,并且所有具有“类别2”类别的产品都具有白色背景颜色。针对特定产品类别的Woocommerce自定义样式?

不幸的是,当我谈到PHP时,我大多无能为力。你能像我是五年级的学生一样向我解释解决方案吗?

感谢提前:)

你需要广告你的主题functions.php文件中的函数:

<!-- language: 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. 此功能将增加产品类别为蛞蝓类别名称为<body>元素,该元素将允许您专门针对该页面的样式。

+0

这工作!非常感谢。 – designer2112