【问题标题】:Add a red asterisk at the end of all attributes labels in Woocommerce variable products在 Woocommerce 变量产品中的所有属性标签末尾添加一个红色星号
【发布时间】:2021-07-12 06:12:35
【问题描述】:

如何在 Woocommerce 中的所有属性标签末尾添加一个红色星号?看起来应该很简单,但我很难弄清楚。不会在functions.php文件中吗?

所需的属性实际上是有效的,因为“添加到购物车”按钮在选择一个选项之前是灰色的。但是,显然我的客户没有意识到这一点,因为他们告诉我我的“添加到购物车”按钮不起作用。因此,如果我可以让他们注意变化下拉菜单,他们可能会意识到必须先选择一个选项,然后才能将商品添加到购物车。

【问题讨论】:

    标签: php wordpress woocommerce required variable-product


    【解决方案1】:

    要在单个变量产品的产品属性标签末尾添加一个红色星号,就像在必填结帐字段中一样,您可以使用以下非常简单的挂钩函数:

    add_filter( 'woocommerce_attribute_label', 'filter_single_variable_product_attribute_label', 10, 3 );
    function filter_single_variable_product_attribute_label( $label, $name, $product ) {
        if ( is_product() ){
            $label .= '&nbsp;<abbr class="required" title="required" style="color:#FF3333;">*</abbr>';
        }
        return $label;
    }
    

    代码位于活动子主题(或活动主题)的functions.php 文件中。经过测试并且可以工作。

    【讨论】:

    • 是的,就是这样!虽然星号是我的主题的字体颜色,但我现在在所有产品变体标签之后都有星号。谢谢!
    • 我已尝试设置您提供的代码的样式,使星号为红色,但没有成功。我应该使用什么类名?
    • 感谢您的快速回复,但任何一个 CSS 都没有改变任何东西。我做错了什么吗? add_filter('woocommerce_attribute_label', 'filter_single_variable_product_attribute_label', 10, 3); function filter_single_variable_product_attribute_label( $label, $name, $product ) { if ( is_product() ){ $label .= ' *'; } 返回$标签; ?>
    猜你喜欢
    • 2018-06-22
    • 2018-05-07
    • 2017-06-26
    • 1970-01-01
    • 2018-07-18
    • 2018-05-04
    • 1970-01-01
    • 2019-03-08
    • 1970-01-01
    相关资源
    最近更新 更多