Hello @emzdesign
The $this is referring the document object, but you have the custom field saved in product meta.
With our Premium Templates extension you can add it very easily inside the product column, this way you don’t need to mess with code:

You shouldn’t make this changes directly on the core templates, because when you update the plugin you will loose them. If you decide to go with the code implementation i recommend you to use a custom template, and read this documentation page: Displaying product custom fields
-
This reply was modified 6 years ago by
alexmigf.
Hi
Thanks for your help. I did look at that link earlier and have tried that way too, but it didn’t work either.
The code I used was:
<?php
if (!empty($item['product'])) {
// replace 'Location' with your custom field name!
$field_name = 'hs_code';
$hs_code = $item['product']->get_meta($field_name,true,'edit');
if ( !empty($hs_code) ) {
echo 'HS Code: '.$hs_code.'';
}
}
?>
Am I missing something there? I am using a custom template as well. Thanks for your help.
Hello @emzdesign
Can you show me the ACF field screen?
I’m not sure why but it says this issue is resolved but it isn’t. How can I change that?
Plugin Contributor
Ewout
(@pomegranate)
Code looks fine to me. Where in the template did you place this? Is this for variable products or for simple products? You could also try using the ACF the_field()/get_field() functions like so:
<?php
if( $hs_code = get_field( 'hs_code', $item['product_id'] ) ) {
echo 'HS Code: '.$hs_code;
}
?>
But note that this will only work properly inside the order items table.
I saw another post with a similar issue where you recommended the Store Toolkit. I installed that plugin and checked the order, and it appears the hs_code isn’t being passed through with the order?
I suppose this is more of an ACF issue than an issue with the WooCommerce PDF Invoices & Packing Slips.
I will get in touch with them to see if there’s a way around it then update this thread with (hopefully) a solution.
@pomegranate forget my last reply – that code you provided worked perfectly! Thank you so much!
Plugin Contributor
Ewout
(@pomegranate)
Glad to hear that @emzdesign !
If you could spare a minute for a plugin review here on ww.wp.xz.cn we’d greatly appreciate it.
All the best with your store and have a fantastic day!