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

时间:2015-08-14 16:55:17

标签: woocommerce

是否有一种简单的方法可以在Woocommerce中为特定产品添加自定义样式?例如,我希望所有类别为“Category1”的产品都具有蓝色页面背景颜色,而所有具有“Category2”类别的产品都具有白页背景颜色。

不幸的是,当涉及到PHP时,我几乎一无所知。你能解释一下这个解决方案,就像我是五年级学生一样吗?

提前致谢:)

1 个答案:

答案 0 :(得分:2)

您需要在主题的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. 此函数将产品类别slug作为类名添加到<body>元素,这将允许您专门针对该页面定位样式。

相关问题