Hide empty custom field from Invoice
-
I’m currently using this code to display a custom field (‘purchase_order’) on the invoice and packing slip.
add_action( 'wpo_wcpdf_after_order_data', 'wpo_wcpdf_purchase_order', 10, 2 ); function wpo_wcpdf_purchase_order ($document_type, $order) { $document = wcpdf_get_document( $document_type, $order ); ?> <tr class="purchase-order"> <th>Purchase Order:</th> <td><?php $document->custom_field('purchase_order'); ?></td> </tr> <?php }
How can I ensure that the title ‘Purchase Order:’ does not display when the custom field is either non existent or empty?
My attempts at wrapping the code in a conditional are not working.
add_action( 'wpo_wcpdf_after_order_data', 'wpo_wcpdf_purchase_order', 10, 2 ); function wpo_wcpdf_purchase_order ($document_type, $order) { $document = wcpdf_get_document( $document_type, $order ); $purchase_order = $document->custom_field('purchase_order'); if (!empty($purchase_order)) { ?> <tr class="purchase-order"> <th>Purchase Order:</th> <td><?php echo $purchase_order; ?></td> </tr> <?php }
Viewing 5 replies - 1 through 5 (of 5 total)
Viewing 5 replies - 1 through 5 (of 5 total)
- The topic ‘Hide empty custom field from Invoice’ is closed to new replies.