Skip to content

Instantly share code, notes, and snippets.

@webtoffee-git
Created July 31, 2024 11:13
Show Gist options
  • Save webtoffee-git/2b56773981a20ab2ab0f5e6cab5a92ba to your computer and use it in GitHub Desktop.
Save webtoffee-git/2b56773981a20ab2ab0f5e6cab5a92ba to your computer and use it in GitHub Desktop.
Code for Displaying Custom Product Names in WooCommerce Invoices for Specific Products and Users - By WebToffee
<?php //Do not copy this line of code
add_filter('wf_pklist_alter_product_name', 'wt_pklist_new_prodct_name_for_user', 10, 5);
function wt_pklist_new_prodct_name_for_user($order_item_name, $template_type, $_product, $order_item, $order) {
$target_product_id = 1186;
$target_user_id = 0;
if ( 'invoice' === $template_type && is_object($_product) && is_object($order) ) {
$product_id = $_product->get_id();
$user_id = $order->get_user_id();
//Change the name of a particular product.
if ( $target_product_id === $product_id ) {
$order_item_name = "new product name for specific product";
}
//Change the name of a particular product in the order made by a particular user.
if ( $target_product_id === $product_id && $target_user_id === $user_id ) {
$order_item_name = "new product name for specific user for a specific product";
}
}
return $order_item_name;
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment