• Resolved onelikenoone

    (@onelikenoone)


    Hi, I need to automatically display a different product name in the invoice, not the original name of the product. I need to do this only for some product. Is there any way?
    Thank you

Viewing 2 replies - 1 through 2 (of 2 total)
  • Thread Starter onelikenoone

    (@onelikenoone)

    A desired solution could also be to show a custom attribute on the invoice instead of the product name.

    Plugin Contributor Ewout

    (@pomegranate)

    This will require some custom coding, but it’s certainly possible if you know a bit of PHP.
    If you only want to change this in the PDF documents produced by this plugin, you could use the wpo_wcpdf_order_item_data filter. Here’s a basic example that will do a simple search/replace:

    
    add_filter('wpo_wcpdf_order_item_data',function( $data, $order, $document_type ){
    	$replace_names = [
    		'Some product' => 'alternative name',
    		'Another product' => 'another alternative',
    	];
    	$data['name'] = str_ireplace(array_keys($replace_names),array_values($replace_names),$data['name']);
    
    	return $data;
    },10,3);
    

    You could do much more advanced replacements based on the order data in $data if you like but that’s a bit beyond the scope of free support.

    Alternatively, if you want to do this WooCommerce wide, you can use the woocommerce_order_item_name filter – this is applied in woocommerce emails, my account etc. too (as well as the invoice). Here’s a basic example (non-functional in this form):

    
    add_filter( 'woocommerce_order_item_name', function ( $item_name, $item ) {
    	// modify $item_name based on the properties/content of $item here
    	return $item_name;
    }, 10, 2);
    

    Hope that helps!

Viewing 2 replies - 1 through 2 (of 2 total)
  • The topic ‘Changing product name’ is closed to new replies.