The goal is to change the name of the item as it gets passed to our payment gateway, but leave it as-is for display on our product pages.
I've tried this in my functions.php:
function change_item_name( $item_name, $item ) {
$item_name = 'mydesiredproductname';
return $item_name;
}
add_filter( 'woocommerce_order_item_name', 'change_item_name', 10, 1 );
But it doesn't seem to be working for me. I feel like I should be passing in an actual item ID or something… I'm a little lost.
Any information on what I'm doing wrong here would be greatly appreciated.
The
woocommerce_order_item_name
filter hook is a front-end hook and is located in:1) WooCommerce templates:
2)WooCommerce Core file:
You have 2 arguments set in your function (the second one is not correct for all templates) and you are declaring only one in your hook. I have tested the code below:
And it works on
But NOT in Cart, Checkout and Backend Order edit pages.
Here is your new code
Code goes in any php file of your active child theme (or theme) or also in any plugin php file.
Now you have change the names everywhere except on Shop archives and product pages…
This code is tested and works on WooCommerce 2.5+ and 3+
This answer has been updated on August 1st 2017 to get a woocommerce compatibility prior versions…