Last active
May 21, 2020 13:45
-
-
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.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
<?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