【问题标题】:Append text to product title on multiple pages in WooCommerce在 WooCommerce 中的多个页面上将文本附加到产品标题
【发布时间】:2020-05-31 12:02:46
【问题描述】:

我正在尝试将文本附加到订单元中的 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;
}

【问题讨论】:

    标签: php wordpress woocommerce product hook-woocommerce


    【解决方案1】:

    根据您的previous question 和这个新问题,我假设您希望看到产品标题调整为“无处不在”。

    重要!您绝对应该阅读以下帖子 明白这是一个普遍的调整,让你最终 不再需要您之前帖子/问题中的代码

    Changing WooCommerce cart item names

    也就是说,你可以开始使用下面的代码来查看以下地方的调整

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

    现在除了商店档案和产品页面之外,您可以在任何地方更改名称……

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

    【讨论】:

      猜你喜欢
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 2023-01-22
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 2019-09-16
      相关资源
      最近更新 更多