• Resolved Atik

    (@onlinetravelgear)


    Hi team,

    Is there a way to generate the invoice automatically when the status changes to “Complete” without attaching the PDF invoice to order complete email.

Viewing 12 replies - 1 through 12 (of 12 total)
  • Plugin Contributor alexmigf

    (@alexmigf)

    Hello @onlinetravelgear

    Yes, you could use a filter hook. Please try this:

    add_filter('wpo_wcpdf_custom_attachment_condition', 'wpo_wcpdf_disable_invoice_attachment', 10, 4);
    function wpo_wcpdf_disable_invoice_attachment( $condition, $order, $email_id, $document_type )
    {
    	if ( !empty($order) && $document_type == 'invoice' && $email_id == 'customer_completed_order' ) {
    		$condition = false;
    	}
    	return $condition;
    }

    If you never worked with filters/actions please read this documentation page: How to use filters.

    • This reply was modified 4 years, 8 months ago by alexmigf.
    Thread Starter Atik

    (@onlinetravelgear)

    Firstly, thank you for your response! ??
    The snipped has does not attach the email to ‘order complete’ email and it also does not create an invoice on status changed to COmpleted.
    I want to create an invoice when status changes to Complete but I do not wish to add that invoice in order complete email.

    Plugin Contributor alexmigf

    (@alexmigf)

    The code snippet, like you said, doesn’t attach the PDF document to the “order completed” email, so I’m assuming that is correct.

    To generate the invoice on order completed you must enable it under PDF Invoices > Documents > Invoice > Attach to.

    Thread Starter Atik

    (@onlinetravelgear)

    I’ve already enable it under PDF Invoices > Documents > Invoice > Attach to.

    Test 1 (with the snippet): Invoice did not generate and order complete email didn’t have any attached invoice.

    Test 2 (without the snippet): Invoice Generated and order complete email had an attached invoice.

    • This reply was modified 4 years, 8 months ago by Atik.
    Plugin Contributor alexmigf

    (@alexmigf)

    Hello @onlinetravelgear

    Sorry, i provide you the wrong hook.

    Please disable the attach to in the settings for completed order status and replace the previous code snippet with this:

    add_action('woocommerce_order_status_completed', 'wpo_wcpdf_create_invoice_number');
    function wpo_wcpdf_create_invoice_number ( $order_id ) {
    	$order = wc_get_order( $order_id );
    	$invoice = wcpdf_get_document( 'invoice', $order, true );
    }

    Let me know how it goes.

    • This reply was modified 4 years, 8 months ago by alexmigf.
    Plugin Contributor Ewout

    (@pomegranate)

    duplicate

    Thread Starter Atik

    (@onlinetravelgear)

    @alexmigf Thanks a ton man. Worked like a charm ??

    Thread Starter Atik

    (@onlinetravelgear)

    Hi there,

    Firstly, thank you so much for sharing this patch.
    I’ve been using this for a while and I noticed that some orders are still being created on order date (on processing status) and not when order status is marked complete.

    PFA screenshot

    Surprisingly, the order before and after this order both have generated invoice correctly on order complete date.

    Plugin Contributor Ewout

    (@pomegranate)

    @onlinetravelgear Your screenshot doesn’t show all the order notes so I can’t tell what happened before june 20th. The only reasons I can think of that would have triggered the creation of this invoice are:

    • An admin clicked the PDF invoice button or did a bulk export, including this order in it (you could prevent this if you set the “disable for:” setting to only the “Completed” order status)
    • If you have changed the “My account” visibility settings to anything other than “only when an invoice is already created/emailed”, your customer could have created it
    • The order was set to the completed order status earlier in the process and then moved “back”
    • An email with the invoice attached was manually sent to your customer
    Thread Starter Atik

    (@onlinetravelgear)

    Hi @pomegranate

    PFA Screenshot of Order log: one –> two –> three –> four

    PFA Screenshot of my settings: First –> Second –> Third

    An admin clicked the PDF invoice button or did a bulk export, including this order in it (you could prevent this if you set the “disable for:” setting to only the “Completed” order status)
    I’m quite confident that this manual error would not have occurred because this error is for around 100+ (out of 5000+) order on my dashboard.

    If you have changed the “My account” visibility settings to anything other than “only when an invoice is already created/emailed”, your customer could have created it
    This is not the case, refer screenshot

    The order was set to the completed order status earlier in the process and then moved “back”
    This is not the case, refer screenshot

    An email with the invoice attached was manually sent to your customer
    This is not the case as there’s no attachment sent, only invoice is created when the order is marked completed

    Plugin Contributor Ewout

    (@pomegranate)

    @onlinetravelgear thanks for sharing that.
    The invoice date and time coincide exactly with the first note in the order, which suggests that the invoice creation was either triggered at the time of the order (if the attachment settings on june 17th had the “New Order (admin email)” enabled) or that the “Invoice date” setting at the time of invoice creation (which would be june 25th if the attachment settings were the same) was set to “Order Date”.

    You mention that 100 out of 5000 orders have this issue – is that including recent orders/invoices (e.g. invoices that have been created since you posted this)?

    The plugin never creates invoices automatically for anything other than email attachments, there are simply no functions for that in the code (at least in the free plugin).

    Thread Starter Atik

    (@onlinetravelgear)

    Ohh! I have a paid version.

Viewing 12 replies - 1 through 12 (of 12 total)
  • The topic ‘Generate invoice on status change without attaching invoice to email’ is closed to new replies.