• Resolved gifiy

    (@gifiy)


    Hello,

    I would like to change the Invoice Date from the Order Date to the Date the order was completed.

    Is there a way to change this setting?

    Kind regards
    gifiy

Viewing 3 replies - 1 through 3 (of 3 total)
  • Plugin Contributor Darren Peyou

    (@dpeyou)

    Hi @gifiy,

    Sorry your message slipped right through us!

    I believe for this purpose, you could hide the Invoice date from the settings in the Document tab, then re-insert the “Completed Date: ” using the _date_completed meta-key. Somewhat following the examples here https://docs.wpovernight.com/woocommerce-pdf-invoices-packing-slips/displaying-a-custom-field/ to display Custom Fields in our PDFs.

    Plugin Contributor Ewout

    (@pomegranate)

    Actually, there’s a better method that changes the invoice date itself, by using a filter:

    add_filter( 'wpo_wcpdf_invoice_get_date', function( $date, $document ) {
    	if ( $document->get_type() == 'invoice' && $order = $document->order ) {
    		if ( $completed_date = $order->get_date_completed() ) {
    			$date = $completed_date;
    		} else { // fallback to order date
    			$date = $order->get_date_created();
    		}
    	}
    	return $date;
    }, 10, 2 );

    If you haven’t worked with code snippets (actions/filters) or functions.php before, read this guide: How to use filters

    If you do prefer to print the “Completed date” as a separate date on the invoice, you should use the official WooCommerce method rather than calling it as a custom field, because technically it’s an order property (which is similar to custom fields, but behaves somewhat different):

    
    // get formatted completed date (fallback to order date)
    $completed_date = $order->get_date_completed() ? $order->get_date_completed()->format( wc_date_format() ) : $order->get_date_created()->format( wc_date_format() )
    

    Hope that helps!

    Thread Starter gifiy

    (@gifiy)

    Perfect, it works like a masterpiece ??
    I really appreciate your support!

Viewing 3 replies - 1 through 3 (of 3 total)
  • The topic ‘Change the Invoice Date from Order Date to Date the order was completed.’ is closed to new replies.