Skip to content

Instantly share code, notes, and snippets.

@gerrgg
Last active May 21, 2020 13:45
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save gerrgg/a1943c6b58d9b2023d437fa80e809440 to your computer and use it in GitHub Desktop.
Save gerrgg/a1943c6b58d9b2023d437fa80e809440 to your computer and use it in GitHub Desktop.
How to include custom meta data and custom fields to Woocommerce-pdf-invoices-packing-slips plugin.
<?php
// hooks into invoice.php
add_action( 'wpo_wcpdf_after_order_data', 'msp_add_meta_data_to_wpo_invoice', 100, 2 );
function msp_add_meta_data_to_wpo_invoice( $type, $order ){
/**
* Adds custom meta data to WPO generated invoice plugin
* DOC: https://docs.wpovernight.com/woocommerce-pdf-invoices-packing-slips/pdf-template-action-hooks/
* @param string $template_type
* @param WC_Order $order
*/
$id = $order->get_order_number();
// Label => custom meta_key added to order
$custom_fields = array(
'AVS Result' => 'mes_avs_result',
'Card Type' => 'mes_card_type',
'Purchase Order' => '_billing_po'
);
// print non-empty fields
foreach( $custom_fields as $label => $meta_key ){
$meta_value = get_post_meta( $id, $meta_key, true );
if( ! empty( $meta_value ) ){
printf( "<p><strong>%s</strong>: %s</p>", $label, $meta_value );
}
}
}
?>
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment