php - 如何将CSS应用于Wordpress/Woocommerce中除某些产品页面之外的所有页面?

标签 php css wordpress woocommerce

我想知道如何将此 CSS 代码应用到我网站上的每个页面,类别为“Category1”的 woocommerce 产品除外。

.custom-single-product .cart, span.woocommerce-Price-amount.amount, a.cart-customlocation.et-cart-info {
    display: none !important;
}

我尝试使用下面的代码使用 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' );

基本上,最终目标是让某些产品能够添加到购物车并显示价格和结帐,但将这些选项和信息隐藏在绝大多数产品和网站上。 谢谢

最佳答案

body:not(.product_cat_Category1) 添加到每个 CSS 规则。所以它应该看起来像这样:

body:not(.product_cat_Category1) .custom-single-product .cart, body:not(.product_cat_Category1) span.woocommerce-Price-amount.amount, body:not(.product_cat_Category1) a.cart-customlocation.et-cart-info {
    display: none !important;
} 

关于php - 如何将CSS应用于Wordpress/Woocommerce中除某些产品页面之外的所有页面?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/51029819/

相关文章:

php - 如何在 WordPress 中显示类别列表及其所有帖子?

php - 带有命名参数的 vsprintf 或 sprintf,或者 PHP 中的简单模板解析

javascript - 加载 CSS 后触发的 jQuery 事件?

html - 在 CSS 中格式化 topnav

html - 如何阻止右键单击 HTML 中的特定区域?

wordpress - 获取头版 Wordpress 的 ID

php - 回显 Javascript 不发出警报

php - 关于 Session var 和共享 SSL 的建议

php - 如何使用post in循环访问表单数据

php - 删除 Woocommerce 产品简短说明