在 WooCommerce 的多个页面上将文本附加到产品标题

Append text to product title on multiple pages in WooCommerce

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

工作

这是我的票价:

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

根据您的 previous question 和这个新问题,我假设您希望看到调整后的产品标题 '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

Changing WooCommerce cart item names

换句话说,您可以开始使用下面的代码来查看以下地方的调整

  • Order-receive(谢谢)页面,
  • 电子邮件通知
  • 我的账户订单>单笔订单详情
  • 购物车和结账以及后端订单编辑页面。

现在除了商店档案和产品页面之外,您已经在所有地方更改了名称……

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