Last active
February 28, 2022 11:18
-
-
Save ChromeOrange/6548750 to your computer and use it in GitHub Desktop.
Modifying Headers in WooCommerce PDF Invoice
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
/** | |
* Modifying Headers | |
* | |
* Add to your theme functions.php | |
*/ | |
add_filter( 'pdf_template_table_headings','custom_pdf_template_table_headings' ); | |
function custom_pdf_template_table_headings( $headers ) { | |
$headers = '<table class="shop_table orderdetails" width="100%">' . | |
'<thead>' . | |
'<tr><th colspan="7" align="left"><h2>' . esc_html__('Order Details', PDFLANGUAGE) . '</h2></th></tr>' . | |
'<tr>' . | |
'<th width="10%" valign="top" align="right">' . __( 'Qty', PDFLANGUAGE ) . '</th>' . | |
'<th width="54%" valign="top" align="left">' . __( 'Product', PDFLANGUAGE ) . '</th>' . | |
'<th width="18%" valign="top" align="right">' . __( 'Price Inc', PDFLANGUAGE ) . '</th>' . | |
'<th width="18%" valign="top" align="right">' . __( 'Total Inc', PDFLANGUAGE ) . '</th>' . | |
'</tr>' . | |
'</thead>' . | |
'</table>'; | |
return $headers; | |
} | |
add_filter( 'pdf_template_line_output' , 'custom_pdf_template_line_output', 10, 2 ); | |
function custom_pdf_template_line_output( $pdflines, $order_id ) { | |
global $woocommerce; | |
$order = new WC_Order( $order_id ); | |
$order_currency = $order->get_currency(); | |
$pdflines = '<table width="100%">'; | |
$pdflines .= '<tbody>'; | |
if ( sizeof( $order->get_items() ) > 0 ) : | |
foreach ( $order->get_items() as $item ) { | |
if ( $item['qty'] ) { | |
$line = ''; | |
// $item_loop++; | |
$_product = $order->get_product_from_item( $item ); | |
$item_name = $item['name']; | |
$item_meta = new WC_Order_Item_Meta( $item['item_meta'] ); | |
if ( $meta = $item_meta->display( true, true ) ) | |
$item_name .= ' ( ' . $meta . ' )'; | |
$line = '<tr>' . | |
'<td valign="top" width="10%" align="right">' . $item['qty'] . ' x</td>' . | |
'<td valign="top" width="54%">' . $item_name . '</td>' . | |
'<td valign="top" width="18%" align="right">' . wc_price( ( $item['line_subtotal'] + $item['line_tax'] ) / $item['qty'], array( 'currency' => $order_currency ) ) . '</td>' . | |
'<td valign="top" width="18%" align="right">' . wc_price( $item['line_subtotal'] + $item['line_tax'], array( 'currency' => $order_currency ) ) . '</td>' . | |
'</tr>' ; | |
$pdflines .= $line; | |
} | |
} | |
endif; | |
$pdflines .= '</tbody>'; | |
$pdflines .= '</table>'; | |
return $pdflines; | |
} | |
/* Close Modifying Headers */ |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Bonjour,
ou on peux mettre le code source dans woocommerce ?
MERCI