Thanks for mentioning that again, @holle75!
I think we overlooked that part! I have updated the code snippet to make it compatible with variable products as well:
/**
* WooCommerce PDF Invoices & Packing Slips:
* Display HS/HSN Code after item meta (if not empty)
*/
add_action( 'wpo_wcpdf_after_item_meta', function( $document_type, $item, $order ) {
if ( isset( $item['product'] ) && is_object( $item['product'] ) ) {
$product = $item['product'];
// If the product is variable, get the parent
if ( $product->is_type( 'variation' ) ) {
$parent_id = $product->get_parent_id();
$product = wc_get_product( $parent_id );
}
// Get the product HS Code
if ( $value = $product->get_meta( '_hs_code' ) ?: $product->get_meta( 'hs_code' ) ) {
echo "<div class=\"hs-code\"><small>HS/HSN Code: {$value}</small></div>";
}
}
}, 10, 3 );
Let me know whether it worked, or you need more tweaks!
Beautiful, Yordan. This works. I highly appreciate your commitment to help.