• Resolved vervelover

    (@vervelover)


    Hi,

    I need to replace product names in the invoice with a name pulled from a product’s custom field. This is because my shop is in Japanese, but the shipping company requires invoices to be 100% English. So I’m creating a custom field to store the english name of the product to use in invoices instead of the Japanese name. Is this possible to achieve with the premium version of your plugin?

    Thanks!
    Alessio

    https://www.ads-software.com/plugins/woocommerce-pdf-invoices-packing-slips/

Viewing 6 replies - 1 through 6 (of 6 total)
  • Plugin Contributor Ewout

    (@pomegranate)

    Hi Alessio,
    Unfortunately this is a bit advanced even for the premium version.
    You can do this with a filter though: wpo_wcpdf_order_item_data

    Here’s an example, you will need the to change the $meta_key to match your custom field (assuming this is stored in the product).

    add_filter( 'wpo_wcpdf_order_item_data', 'wpo_wcpdf_english_product_name', 10, 2 );
    function wpo_wcpdf_english_product_name ( $item_data, $order) {
    	$meta_key = 'english_name'; // replace this with the name of the custom field
    	$english_name = get_post_meta( $item['product_id'], $meta_key, true );
    	if ( !empty($english_name) ) {
    		$item_data['name'] = $english_name;
    	}
    	return $item_data;
    }

    Hope that helps!
    Ewout

    Thread Starter vervelover

    (@vervelover)

    Hi,

    thank you for your reply, this is premium support! I don’t mind to use a filter, it’d be perfectly fine. I’m buying the plugin right away.

    Thanks!
    Alessio

    Plugin Contributor Ewout

    (@pomegranate)

    You’re welcome, glad I could help ??

    Ewout

    Thread Starter vervelover

    (@vervelover)

    Hi,

    sorry to bother again,
    I tried the above code after entering the custom keys (I put the code in functions.php), but for some reason the name haven’t changed in the invoice..

    Thank you for your help
    Alessio

    Thread Starter vervelover

    (@vervelover)

    Hi,

    nevermind I found the issue, I guess the code should be $item[‘name’] instead of $item_data[‘name’], but I figured out how to do this all by editing my custom template.

    Thanks!
    Alessio

    Plugin Contributor Ewout

    (@pomegranate)

    Hi! I’m not sure why it didn’t work, reviewing the code it looks to me like this should work. There is no $item variable in that action, so $item_data should work.

    I recommend using the filter rather than editing the template, as this is much more update proof. If this works for you, that’s fine too of course ??

    Have a fantastic day!
    Ewout

Viewing 6 replies - 1 through 6 (of 6 total)
  • The topic ‘replace product name with custom field’ is closed to new replies.