【问题标题】:Handle text Colour in WooCommerce variations?在 WooCommerce 变体中处理文本颜色?
【发布时间】:2017-12-13 07:33:59
【问题描述】:

有一个问题不知道如何解决。有product(XS 变体)是“无库存”但已选择“允许但通知客户”所以想要以黄色制作该变体,如下图所示。

有这个功能:

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;
}

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

【问题讨论】:

    标签: css wordpress function woocommerce


    【解决方案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>

    【讨论】:

    • 类被命名为:sbOptions 我不知道如何处理?任何建议。已在第一篇文章中发布了链接。
    • 我已经在.sbOptions li.sbDisabled a中添加了这个css color: red !important;并且我在相关的li中添加了“sbDisabled”,你只需要在一些li中添加“sbDisabled”来影响链接
    • 如何处理仅适用于延期交货的产品?我没有看到任何只指向该组产品的选择器?我无法修改这些类,因为是从 WooCommerce 自动生成的。其他建议?
    • 哈,不能修改js或者php? if (stock == true) $color = "green", else $color = red 并用...&lt;li class=$color&gt;...替换... &lt;li&gt;...
    • 处理“in-stock”变量没有问题,处理“backorders_require_notification”类有问题,因为WooCommerce没有为那个东西提供类。目前所有具有:允许延期交货和允许但通知客户的变体都标有绿色。我需要用黄色标记“允许但通知客户”。有可能吗?
    猜你喜欢
    • 2019-07-05
    • 1970-01-01
    • 2016-02-07
    • 2022-01-15
    • 1970-01-01
    • 2020-08-13
    • 1970-01-01
    • 1970-01-01
    • 2013-02-22
    相关资源
    最近更新 更多