I am working on a WooCommerce site and need to display custom meta data for each product on the packing slips generated by a PDF creator plugin. I have successfully added a custom meta field to ordered products (example of the meta field setup: HERE ).
I want to include this custom meta data on the packing slips like this one here.
However, when I try to implement this by modifying the PDF creator plugin, it does not work as expected. Here is the code I’ve added to plugins settings.php file:
$pdf_invoice_order_ids as $pdf_invoice_order_id) {
$billingfname = $order->billing_first_name;
$billinglname = $order->billing_last_name;
$billingcompany = $order->billing_company;
$billingaddress = $order->billing_address_1;
$billingcountry = $order->billing_country;
$billingemail = $order->billing_email;
$billingphone = $order->billing_phone;
$shippingfname = $order->shipping_first_name;
$shippinglname = $order->shipping_last_name;
$shippingcompany = $order->shipping_company;
$shippingaddress = $order->shipping_address_1;
$shippingcountry = $order->shipping_country;
$shippingphone = $order->shipping_phone;
$denememeta = $item->get_meta_data('custom_meta_key', true); //this is the code i've added.
$paymentmethod = $order->payment_method_title;
$html .= '<table width="640" cellpadding="0" cellspacing="0" border="0">
<tr>
<td width="320">
<table width="100%" cellpadding="0" cellspacing="0" border="0">
<tr>
<td style="font-weight:bold; font-size:'.$templatefontsize.'; color:'.$templatefontcolor.';">REÇETE '.$denememereceteli.'</td>
</tr>
and then i use this variable in:
$html.='<tr style="background-color: #f8f8f8;">
<td style="border-bottom:1px solid gray;" class="heading_cellsdata">'.get_the_post_thumbnail($item['product_id'], array( 30, 30)).' '.$item['name'].' '.$denememeta.'</td> //here
<td style="border-bottom:1px solid gray;" class=" center heading_cellsdata">'.$item['qty'].'</td>
</tr>';
Issues Encountered:
The meta data does not show up on the PDF, The meta fields are blank on the packing slips.
Questions:
- How can I correctly retrieve and display the custom meta data in the packing slip PDF?
- Are there specific hooks or functions in WooCommerce that I should use to ensure the custom meta data is accurately pulled into the PDF creation process?
I appreciate any help or suggestions you can provide!
New contributor