Reputation: 11
I am trying to add a custom template to get the ATUM location to show in the packing slips. I have tried a couple of codes to retrieve the information but nothing shows up. I do not get any error I just will not get the information. The ATUM location works fine because I do get it on the orders in woocommerce.
What I am doing wrong to retrieve the information from atum?
This is what I have tried to add:
add_action( 'wpo_wcpdf_after_order_data', 'wpo_wcpdf_atum_location', 10, 2 );
function wpo_wcpdf_atum_location($template_type, $order) {
if ($template_type == 'packing-slip') {
$document = wcpdf_get_document( $template_type, $order );
$atum_location = get_post_meta( $order->get_id(), '_atum_location', true );
if ( ! empty( $atum_location ) ) {
?>
<tr class="atum-location">
<th>ATUM Location:</th>
<td><?php echo esc_html( $atum_location ); ?></td>
</tr>
<?php
}
}
}
<?php
$locations = wp_get_object_terms ( $summary_item, 'atum_location', array( 'fields' => 'names' ) );
$locations_list = ! empty( $locations ) ? implode( ', ', $locations ) : '–';
?>
<?php echo esc_html( $locations_list ) ?>
Here is the whole code for the template with one code I tried:
<tbody>
<?php foreach ( $this->get_order_items() as $item_id => $item ) : ?>
<tr class="<?php echo esc_html( $item['row_class'] ); ?>">
<td class="product">
<p class="item-name"><?php echo esc_html( $item['name'] ); ?></p>
<?php do_action( 'wpo_wcpdf_before_item_meta', $this->get_type(), $item, $this->order ); ?>
<div class="item-meta">
<?php if ( ! empty( $item['sku'] ) ) : ?>
<p class="sku"><span class="label"><?php $this->sku_title(); ?></span> <?php echo esc_attr( $item['sku'] ); ?></p>
<?php endif; ?>
<?php if ( ! empty( $item['weight'] ) ) : ?>
<p class="weight"><span class="label"><?php $this->weight_title(); ?></span> <?php echo esc_attr( $item['weight'] ); ?><?php echo esc_attr( get_option( 'woocommerce_weight_unit' ) ); ?></p>
<?php endif; ?>
<?php if ( ! empty( $location['wp_list_filter'] ) ) : ?>
<p class="item_location"><span class="inventory_labels"><?php $this->inventory_labels(); ?></span> <?php echo esc_html( $inventory_labels); ?><?php echo esc_html( get_option( 'get_location_labels' ) ); ?></
<?php endif; ?>
<!-- ul.wc-item-meta -->
<?php if ( ! empty( $item['meta'] ) ) : ?>
<?php echo wp_kses_post( $item['meta'] ); ?>
<?php endif; ?>
<!-- / ul.wc-item-meta -->
</div>
<?php do_action( 'wpo_wcpdf_after_item_meta', $this->get_type(), $item, $this->order ); ?>
</td>
<td class="quantity"><?php echo esc_html( $item['quantity'] ); ?></td>
</tr>
<?php endforeach; ?>
</tbody>
Upvotes: 1
Views: 32
Reputation: 254353
Since Few years High Performance Order Storage (HPOS) is now enabled by default, which means that Orders data are now located on custom WooCommerce database tables, so you need to replace in your code all post and postmeta WordPress functions with WooCommerce dedicated methods to be used on the WC_Order object.
Which means that in your 1st code attempt, you have to replace:
$atum_location = get_post_meta( $order->get_id(), '_atum_location', true );
with:
$atum_location = $order->get_meta('_atum_location');
So in your code:
add_action( 'wpo_wcpdf_after_order_data', 'wpo_wcpdf_atum_location', 10, 2 );
function wpo_wcpdf_atum_location( $document_type, $order ) {
if ( 'packing-slip' != $document_type ) return; // Target only Packing slip
if ( $atum_location = $order->get_meta('_atum_location') ) {
printf('<tr class="atum-location">
<th>%s:</th>
<td>%s</td>
</tr>', esc_html__('ATUM Location'), esc_attr($atum_location) );
}
}
It should work.
Related:
Upvotes: 1