1

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 !

Jerng Yue
  • 23
  • 6
  • Please elaborate by giving a more detailed example and describe exactly what steps you took and what didn't work as expected. – herrbischoff Jul 10 '17 at 18:28
  • I used this code by @LoicTheAztec – Jerng Yue Jul 10 '17 at 18:31
  • 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 ); } } – Jerng Yue Jul 10 '17 at 18:31
  • They worked great 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. – Jerng Yue Jul 10 '17 at 18:32
  • This is too complicated as it depend of the payment gateway integration available hooks (I think)… You can look at the [function `process_checkout()` in WC_Checkout source code](https://docs.woocommerce.com/wc-apidocs/source-class-WC_Checkout.html#895)… but is not going really to help you. The changes to make are in your related payment gateways code. – LoicTheAztec Jul 11 '17 at 02:42
  • Thanks @LoicTheAztec , I wonder if it is possible to make the code run when the gateway is selected during checkout? In that way everything will work as normal until the gateway is selected? I believe that might be the closest that I can achieve? – Jerng Yue Jul 11 '17 at 09:27

0 Answers0