• Resolved felbar77

    (@felbar77)


    Hi

    If you would be so kind, I have an external service that attaches tax numbers to woocommerce order when they are in status “completed”, after that, it changes order to “fiscalized”. How can I create an invoice on this custom status change, and email it then to user?

    I can see my custom order status (fiscalized) in your plugin only on dropdown – selector list “disable for” in documents tab, but cannot see it in list “attach to”.

    Could you afford some time and send a functions.php piece of code to add this status (fiscalized) to “attach to” list?

    thank you.
    H.

Viewing 5 replies - 1 through 5 (of 5 total)
  • Plugin Contributor kluver

    (@kluver)

    Hi @felbar77,

    The ‘Attach to’ option will let you automatically generate and attach an invoice to one of the WooCommerce emails. So if your custom order status does not trigger an email you can’t attach it.

    You can however create an invoice programmatically when the order status changes to your custom order status. In the example below I used ‘fiscalized’ as the order status that triggers invoice creation:

    add_action('woocommerce_order_status_fiscalized', 'wpo_wcpdf_create_invoice_on_custom_order_status', 20, 2);
    function wpo_wcpdf_create_invoice_on_custom_order_status( $order_id, $order ) {
    	$invoice = wcpdf_get_invoice( $order, true );
    	$invoice->get_pdf();
    }
    Thread Starter felbar77

    (@felbar77)

    Hi thanks for the reply.
    I have managed to get it attached to custom order status.
    However, I have this issue, here is the flow explained:
    1. customer selects product
    2. invoice is generated on new order (admin) – so that I get invoice number for further steps /step 4 external service.
    3. customer pays – woocommerce status changes to completed
    4. additional plugin on completed sends info to external service, returns tax verification numbers…
    5. Tax numbers are added to custom fields and displayed on invoice
    qt the same time – Order changes status to “fiscalized”
    7. On this status, woocommerce sends email as done with invoice attached.

    Now the issue – attached invoice has no tax numbers visible.
    Woocommerce products in the dashboard show tax numbers on pdf…
    So, i guess I send email on status change to fiscalized, but with pdf created initially on order, and before numbers get on invoice…

    Question: can you help me with order of execution (trigger email after all done, or with some delay or something?)

    Plugin Contributor Ewout

    (@pomegranate)

    Glad to hear you managed to attach the PDF to the custom status email!

    For your new issue, I think you’l need to prioritize step 4 somehow. We don’t control the order of execution here, WooCommerce determines when the email is sent (which is primarily triggered by status changes), and our plugin merely hooks into this process…

    Thread Starter felbar77

    (@felbar77)

    Sometimes a word is enough to solve the issue…
    In this case it was “prioritize”
    changed email sending to 999.
    Works like a charm. Thank you for your assistance!!!

    Thread Starter felbar77

    (@felbar77)

    Spoke too soon – email sending still does not work correctly – opening new issue with different subject and part of the process.

Viewing 5 replies - 1 through 5 (of 5 total)
  • The topic ‘Attach invoice to custom status’ is closed to new replies.