douliedai4838 2017-07-10 18:14
浏览 74

更改WooCommerce项目名称

I don't have 50 reputation on stack overflow, so I can't comment on post. To ask a question I gotta make a new question unfortunately :/

So, from here :
Changing WooCommerce cart item names
OP asked about changing WooCommerce cart item names.

The answer below, which
@https://stackoverflow.com/users/3730754/loictheaztec reply helped me but it isn't complete enough..

I've tested the code he gave,

add_filter( 'woocommerce_before_calculate_totals', 'custom_cart_items_prices', 10, 1 );
function custom_cart_items_prices( $cart_object ) {
    if ( is_admin() && ! defined( 'DOING_AJAX' ) )
        return;

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

        // Get the product name (item name)
        $id = $cart_item['data']->get_name();

        // THE NEW NAME
        $new_name = 'mydesiredproductname';

        // Set your cart item name
        $cart_item['data']->set_name( $new_name );
    }
}

it works great, for the code above on the cart page, checkout page customer invoice page and admin order page is changed to "mydesiredproductname" but I want the Cart Page, the Checkout Page, the customer invoice page and the admin order page to remain the same, only thing is changed is the item name that is submitted to payment gateway. Wonder if that is possible? Or what is the closest that I can achieve?

ps: I tested is_cart and also is_checkout function, for is_cart the cart is unchanged, for is_checkout the checkout page is unchanged.

Any help would be greatly appreciated Thanks !

  • 写回答

0条回答 默认 最新

    报告相同问题?

    悬赏问题

    • ¥15 求解O-S方程的特征值问题给出边界层布拉休斯平行流的中性曲线
    • ¥15 谁有desed数据集呀
    • ¥20 手写数字识别运行c仿真时,程序报错错误代码sim211-100
    • ¥15 关于#hadoop#的问题
    • ¥15 (标签-Python|关键词-socket)
    • ¥15 keil里为什么main.c定义的函数在it.c调用不了
    • ¥50 切换TabTip键盘的输入法
    • ¥15 可否在不同线程中调用封装数据库操作的类
    • ¥15 微带串馈天线阵列每个阵元宽度计算
    • ¥15 keil的map文件中Image component sizes各项意思