Skip to content

Instantly share code, notes, and snippets.

@wpweb101
Last active February 19, 2019 09:11
Show Gist options
  • Select an option

  • Save wpweb101/f726948ea3809bb5059d0d0952f0ed28 to your computer and use it in GitHub Desktop.

Select an option

Save wpweb101/f726948ea3809bb5059d0d0952f0ed28 to your computer and use it in GitHub Desktop.
WooCommerce Pdf Voucher - Display order meta without label
<?php
/**
* Adding order meta value to the Custom shortcode in PDF voucher
*/
function woo_vou_pdf_order_items_meta_shortcodes( $voucher_template_html, $orderid, $item_key, $items, $voucodes, $productid) {
$hidden_order_itemmeta = apply_filters( 'woocommerce_hidden_order_itemmeta', array(
'_qty',
'_tax_class',
'_product_id',
'_variation_id',
'_line_subtotal',
'_line_subtotal_tax',
'_line_total',
'_line_tax',
'method_id',
'cost',
)
);
$html = '';
if ( !empty( $items ) ){
$html = '<table cellspacing="0" style="width:100%;">';
foreach ( $items as $i_key => $item ) {
if( $item_key != $i_key )
continue;
if( $meta_data = $item->get_formatted_meta_data( '' ) ){
foreach ( $meta_data as $meta_id => $meta ) {
if ( in_array( $meta->key, $hidden_order_itemmeta, true ) ) {
continue;
}
$html .= '<tr>
<td>'. $meta->display_value .'</td></tr>';
}
}
}
$html .= '</table>';
}
$voucher_template_html = str_replace( '{order_items_meta}', $html, $voucher_template_html );
return $voucher_template_html;
}
// Add filter to replace voucher template shortcodes in download pdf
add_filter('woo_vou_pdf_template_inner_html', 'woo_vou_pdf_order_items_meta_shortcodes', 10, 6 );
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment