Plugin Contributor
kluver
(@kluver)
Hi @faisalzaabi,
The easiest way to display values from custom checkout fields is with our Premium Templates extension. This will give you access to the Customizer that will let you add custom fields with a custom block.
Alternatively you can also achieve this with an action hook by following this guide: Displaying a custom field
In both cases you need the correct meta key of your AWB number. If you are having trouble finding the meta key you can follow this guide: Finding WooCommerce custom fields
Dear @kluver
Thanks for rechout I have tried the below code but it didn’t work `add_action( ‘wpo_wcpdf_after_order_data’, ‘wpo_wcpdf_order_data’, 10, 2 );
function wpo_wcpdf_shipping_tracking($template_type, $order) {
if ($template_type == ‘invoice’) {
if ( $tracking_items = $order->get_meta(‘_awb_no’) ) {
?>
<tr class=”tracking-item”>
<th>Tracking:</th>
<td>
<?php
foreach( $tracking_items as $tracking_item ) {
echo esc_html( $tracking_item[‘_awb_no’] ).”<br>”;
echo esc_html( $tracking_item[‘_awb_no’] );
}
?>
</td>
</tr>
<?php
}
}
}`
The metadata string to retrieve is “_awb_no”
Plugin Contributor
Ewout
(@pomegranate)
It looks like you linked the action hook to the function wpo_wcpdf_order_data but you named the function above wpo_wcpdf_shipping_tracking. This needs to match up for the function to be executed. Do note that the code you used here is specific to a certain data structure (in array form), I’m not sure if that was on purpose? Because it seems you’re trying to get the same data here with different methods. If you’re not sure about this I recommend hiring a web developer.
Thanks @pomegranate
I have updated but it didn’t retrieve any. the code
add_action( ‘wpo_wcpdf_after_order_data’, ‘wpo_wcpdf_shipping_tracking’, 10, 2 );
function wpo_wcpdf_shipping_tracking($template_type, $order) {
if ($template_type == ‘invoice’) {
$order_id = $order->get_id();
$tracking_items = get_post_meta( $order_id, ‘_wc_shipment_tracking_items’, true );
echo ‘<tr class=”tracking”>’;
echo ‘<th>Tracking:</th>’;
foreach( $tracking_items as $tracking_item ) {
echo ‘<td>’.esc_html( $tracking_item[‘_awb-no’] ).'</td>’;
echo ‘<td>’.esc_html( $tracking_item[‘_awb_no’] ).'</td>’;
}
echo ‘</tr>’;
}
}
Plugin Contributor
Ewout
(@pomegranate)
In that case the structure of your data is probably different, I recommend hiring a webdeveloper for this.