在WooCommerce的多个页面上将文本追加到产品标题 [英] Append text to product title on multiple pages in WooCommerce

查看:126
本文介绍了在WooCommerce的多个页面上将文本追加到产品标题的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我正在尝试在订单元中将文本附加到WooCommerce产品标题中-如果产品具有特定标签.我在工作

I'm trying to append text to WooCommerce product title in the order meta - if products has a specific tag. I'm working from

"在Woocommerce Admin,订单和电子邮件中显示自定义付款字段"

这就是我的票价:

add_filter( 'woocommerce_get_order_item_totals', 'add_udstilling_below_cart_item_name', 10, 3 );
function add_udstilling_below_cart_item_name( $total_rows, $order, $tax_display ) {;

    $new_total_rows = [];

    foreach($total_rows as $key => $total ){
        $new_total_rows[$key] = $total;


        }
    }

    return $new_total_rows;
}

推荐答案

基于您的

Based on your previous question and this new question, I assume that you would like to see the product title adjusted 'everywhere'.

重要!!您绝对应该阅读以下文章: 了解这是一项一般性调整,因此您最终 不再需要您以前的帖子/问题中的代码

IMPORTANT!! You should definitely read the following post to understand that this is a general adjustment, so that you ultimately no longer need the code from your previous post / question

更改WooCommerce购物车商品名称

换句话说,您可以开始使用以下代码在以下位置查看调整

In other words, you can start using the code below to see the adjustment in the following places

  • 订单接收(谢谢)"页面,
  • 电子邮件通知
  • 我的帐户订单>单个订单详细信息
  • 购物车结帐和后端订单编辑页面.

现在,除了商店档案"和产品页面上的所有位置之外,您都已经更改了名称...

function add_udstilling_order_item_name( $cart ) {
    if ( is_admin() && ! defined( 'DOING_AJAX' ) )
        return;

    if ( did_action( 'woocommerce_before_calculate_totals' ) >= 2 )
        return;

    // Loop through cart items
    foreach ( $cart->get_cart() as $cart_item ) {

        // Get an instance of the WC_Product object
        $product = $cart_item['data'];

        // Get product id
        $product_id = $cart_item['product_id'];

        if( method_exists( $product, 'set_name' ) && has_term( 'udstillingsmodel', 'product_tag', $product_id ) ) {
            $product->set_name( $product->get_name() . '(test)' );
        }
    }
}
add_action( 'woocommerce_before_calculate_totals', 'add_udstilling_order_item_name', 10, 1 );

这篇关于在WooCommerce的多个页面上将文本追加到产品标题的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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