• Resolved grrog

    (@grrog)


    Hi
    I found the following snippet on this forum and it works fine.

    add_action( 'wpo_wcpdf_after_settings_page', 'wcpdf_invoice_number_store_debug_tools', 9, 2 );
    function wcpdf_invoice_number_store_debug_tools( $tab, $section ){
    	global $wpdb;
    	if ($tab !== 'debug') {
    		return;
    	}
    	$store_name = "invoice_number";
    	$table_name = "{$wpdb->prefix}wcpdf_{$store_name}"; // i.e. wp_wcpdf_invoice_number
    	$results = $wpdb->get_results( "SELECT * FROM {$table_name}" );
    	echo "<table>";
    	echo "<tr><th>invoice number</th><th>order ID</th><th>order date</th></tr>";
    	foreach ($results as $result) {
    		printf("<tr><td>%s</td><td>%s</td><td>%s</td></tr>", $result->id, $result->order_id, $result->date);
    	}
    	echo '</table>';

    I have two questions:
    – how to have separate tables for each month?
    – and how to have the invoice numbers as defined in the Documents > Number format settings?

    I tried many things to customize this code but none worked, my PHP skills are not very good 😉
    Can someone help me please? Thanks

Viewing 1 replies (of 1 total)
  • Plugin Contributor Ewout

    (@pomegranate)

    Hi! This snippet is only meant for debugging and not suitable as a ‘list of invoice numbers’. The reason for this is that every time you have to change the ‘next invoice number’ setting, this list will be cleared. And as you noticed, this list only takes the raw, unformatted invoice numbers.

    If you want to read the invoice numbers for a specific date range, you have to query the orders themselves. Here’s an example that takes a from and to date (2019-01-01...2019-01-31 in the example):

    
    add_action( 'wpo_wcpdf_after_settings_page', 'wcpdf_invoice_number_list', 9, 2 );
    function wcpdf_invoice_number_list( $tab, $section ){
    	$args = array(
    		'return'       => 'ids',
    		'type'         => 'shop_order',
    		'limit'        => -1,
    		'date_created' => '2019-01-01...2019-01-31',
    	);
    	$order_ids = wc_get_orders( $args );
    
    	echo "<table>";
    	echo "<tr><th>Invoice Number</th><th>Order Number</th><th>Order Date</th></tr>";
    	foreach ($order_ids as $order_id) {
    		$order = wc_get_order( $order_id );
    		printf("<tr><td>%s</td><td>%s</td><td>%s</td></tr>", $order->get_meta('_wcpdf_invoice_number'), $order->get_order_number(), $order->get_date_created()->date_i18n('Y-m-d'));
    	}
    	echo '</table>';
    }
    

    This is somewhat beyond the free support of this plugin though, if you need to export this data I recommend looking for an order exporter plugin that can export order meta too (using the _wcpdf_invoice_number meta field).

    Good luck!

Viewing 1 replies (of 1 total)

The topic ‘Customize code snippet’ is closed to new replies.