Last active
September 26, 2018 05:53
-
-
Save wpweb101/9710636d4b5c008f14cc9995af4cd1e0 to your computer and use it in GitHub Desktop.
WooCommerce Pdf Vouchers - Create custom shortcode for display order item meta download PDF
This file contains hidden or 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 | |
| /** | |
| * 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><strong>'.wp_kses_post( $meta->display_key ) .':</strong> '. wp_strip_all_tags ($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