处理WooCommerce变体中的文字颜色?

时间:2017-07-09 14:09:14

标签: css wordpress function woocommerce

有一个问题不知道如何解决。有product(XS变体)是"非库存"但已选择"允许但通知客户"所以想要将这种变化变成黄色,如下图所示。

enter image description here

有这个功能:

add_filter( 'woocommerce_variation_is_active', 
'grey_out_variations_when_is_backorder', 10, 2 );
function grey_out_variations_when_is_backorder( $grey_out, $variation ) {

if ( ! $variation->is_in_stock() && $variation-
 >backorders_require_notification() )
$grey_out = false; // Here text variation need to be yellow.

return $grey_out;
}

但没有解决任何问题,因为灰度只能获得2个值,无论是真还是假。所以我使用了这个CSS:

.sbOptions li span.sbDisabled {
 color:red!important;
 }
.sbOptions li a {
color:green!important;
}

因此可以仅控制灰度和灰度变化。我想做的第三种选择是不可能的。想要的变化是:“缺货”+“允许,延期交货,但通知”=黄色背景&可以选择。目前,变化是绿色的,因为我没有找到一种方法如何处理这些变化的颜色。感谢

1 个答案:

答案 0 :(得分:1)

我没有您的代码,但您可以测试一下吗? 使用子类,或在元素检查器

中检查您的类是否受影响



.content {
background:gray;
padding:5px;
margin:5px 0;
}

.content div {
  margin:5px 0;
}

.content div.blue {
  color:blue;
}

.content div.red {
  color:red;
}

.content.test div {
  color:yellow !important;
}

<div class="content">
  <div class="red">Test</div>
  <div class="blue">Test</div>
  <div>Test</div>
</div>

<div class="content test">
  <div class="red">Test</div>
  <div class="blue">Test</div>
  <div>Test</div>
</div>
&#13;
&#13;
&#13;