• Resolved masherbrum

    (@masherbrum)


    Hi,

    Thank you for this plugin.
    I just installed it in order to generate pdf invoices of past year orders.
    When generating the invoices, the date is set as today, whereas I need it to be the date when the order was confirmed.
    Is there any way to change this ?
    (I mean not manually because I have hundreds of them.)

    Many thanks for your help.
    Best regards,
    Boris

    • This topic was modified 6 years ago by masherbrum.
Viewing 2 replies - 1 through 2 (of 2 total)
  • Plugin Contributor Ewout

    (@pomegranate)

    Hi! You can resolve this with a small code snippet. I have two flavors for you:

    1) Use the completed date (this only works if this was set for those orders!)

    
    add_action( 'wpo_wcpdf_invoice_get_date', 'wpo_wcpdf_order_date_as_invoice_date', 10, 2 );
    function wpo_wcpdf_order_date_as_invoice_date( $date, $document ) {
        if ($document->get_type() == 'invoice' && !empty($document->order)) {
            if( $date_completed = $document->order->get_date_completed() ) {
                $date = $date_completed;
    		}
        }
        return $date;
    }
    

    2) Use the order date (since not all orders may have a ‘completed’ date set):

    
    add_action( 'wpo_wcpdf_invoice_get_date', 'wpo_wcpdf_order_data_as_invoice_date', 10, 2 );
    function wpo_wcpdf_order_data_as_invoice_date( $date, $document ) {
        if ($document->get_type() == 'invoice' && !empty($document->order)) {
            $date = $document->order->get_date_created();
        }
        return $date;
    }
    

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

    Hope that helps!

    Thread Starter masherbrum

    (@masherbrum)

    Thank you very much Ewout for your help and these snippets !

    Best regards,

Viewing 2 replies - 1 through 2 (of 2 total)
  • The topic ‘Change invoice date’ is closed to new replies.