Created
October 27, 2020 09:55
-
-
Save webdados/b4ff5eaba6bd30044d33318aff45a93d to your computer and use it in GitHub Desktop.
Add InvoiceXpress documents to WooCommerce order list
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 | |
add_filter( 'manage_edit-shop_order_columns', 'woocommerce_ixpro_invoice_order_list_column_header' ); | |
function woocommerce_ixpro_invoice_order_list_column_header( $columns ) { | |
$columns['ixpro_docs'] = __( 'InvoiceXpress', 'webdados-toolbox' ); | |
return $columns; | |
} | |
add_action( 'manage_shop_order_posts_custom_column', 'woocommerce_ixpro_invoice_order_list_column_value' ); | |
function woocommerce_ixpro_invoice_order_list_column_value( $column ) { | |
global $post; | |
if ( 'ixpro_docs' === $column ) { | |
if ( $order = wc_get_order( $post->ID ) ) { | |
$issued_documents = array(); | |
$documents = array( | |
'invoice' => __( 'Invoice', 'woo-billing-with-invoicexpress' ), | |
'simplified_invoice' => __( 'Simplified invoice', 'woo-billing-with-invoicexpress' ), | |
'invoice_receipt' => __( 'Invoice-receipt', 'woo-billing-with-invoicexpress' ), | |
'credit_note' => __( 'Credit note', 'woo-billing-with-invoicexpress' ), | |
'receipt' => __( 'Receipt', 'woo-billing-with-invoicexpress' ), | |
'quote' => __( 'Quote', 'woo-billing-with-invoicexpress' ), | |
'proforma' => __( 'Proforma', 'woo-billing-with-invoicexpress' ), | |
'transport_guide' => __( 'Delivery note', 'woo-billing-with-invoicexpress' ), | |
'devolution_guide' => __( 'Return delivery note', 'woo-billing-with-invoicexpress' ) | |
); | |
foreach ( $documents as $doc => $label ) { | |
$docref = $order->get_meta( 'hd_wc_ie_plus_'.$doc.'_sequence_number' ); | |
if ( empty( $docref ) ) $docref = $order->get_meta( 'hd_wc_ie_plus_'.$doc.'_id' ); //Backward compatibility | |
if ( ! empty( $docref ) ) { | |
$issued_documents[] = $doc; | |
if ( ! $link = $order->get_meta( 'hd_wc_ie_plus_'.$doc.'_pdf' ) ) { | |
$link = $order->get_meta( 'hd_wc_ie_plus_'.$doc.'_permalink' ); | |
} | |
echo '<div style="line-height: 1em; margin-bottom: 0.25em;"><small>'.$label.': <strong><a href="'.esc_url( $link ).'" target="_blank">'.$docref.'</a></strong></small></div>'; | |
} | |
} | |
} | |
} | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment