在WooCommerce中的特定产品属性标签旁边添加自定义文本 [英] Adding a custom text next to a specific product attribute label in WooCommerce

查看:0
本文介绍了在WooCommerce中的特定产品属性标签旁边添加自定义文本的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

尝试在不编辑WooCommerce页面模板的情况下在标题/标签旁边添加文本(最好在div内)

伪码:

function my_text_after_variation (){
  if attribute pa_size exists {
    echo label for pa_size;
    echo <div> MY TEXT </div>;
}else{
   return;
}};

我们非常欢迎您的帮助。

推荐答案

若要显示紧跟在特定属性标签名称后面的自定义文本,您将使用woocommerce_attribute_label专用筛选器挂钩中挂接的自定义函数,方法如下:

add_filter( 'woocommerce_attribute_label', 'custom_attribute_label', 10, 3 );
function custom_attribute_label( $label, $name, $product ) {
    $taxonomy = 'pa_'.$name;

    if( $taxonomy == 'pa_size' )
        $label .= '<div class="custom-label">' . __('MY TEXT', 'woocommerce') . '</div>';

    return $label;
}

代码放在活动子主题(或活动主题)的函数.php文件中。

已测试并正常工作。

这篇关于在WooCommerce中的特定产品属性标签旁边添加自定义文本的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
相关文章
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆