• Resolved mom4i911024

    (@mom4i911024)


    Hey there,
    I was wondering if it’s possible to attach the invoice PDF to the order confirmation email that’s generated by WooCommerce? I want to include it there instead of sending a separate email only with the invoice. Also, would it be possible to include invoice information inside the order confirmation email, such as the invoice number?

Viewing 7 replies - 1 through 7 (of 7 total)
  • Plugin Author vendidero

    (@vendidero)

    Hi there,

    you could set the automation settings so that the invoice is being generated when the order confirmation is being sent. The problem with this approach is, that the invoice cannot be generated asynchronously which might lead to longer loading times after the customer submits the order (e.g. before being redirected to the thankyou/payment page). See: https://vendidero.de/dokument/rechnungen-automatisch-erstellen

    Additional information is not added to the email – I guess you’d need help from a webdev to add custom invoice information to this specific email.

    PS: Could you please use our help desk on support on our professional version? https://vendidero.de/dashboard/help-desk

    Best,
    Dennis

    Thread Starter mom4i911024

    (@mom4i911024)

    Hey, thanks a lot for the input, I’ve adjusted the Germanized settings and now the invoice PDF is being generated and attached to the transactional email when the order confirmation is being sent.

    The problem, however is with the additional information I’m trying to add to the email. I’ve modified the customer-processing-order.php template by adding a bit of text and some invoice information. My custom text is showing, but the invoice information is not. Seems like at the time of the creation of the email, I’m not able to grab the invoice object properly or it’s just not ready to use yet at that point. Which is weird, because the PDF attachment of the invoice is in the email, but the information I’m trying to access inside the template is not showing. Here’s a short example of what I’ve tried using:

    $invoice = wc_gzdp_get_order_last_invoice($order);
    	
    if ($invoice) {
        $invoice_number = $invoice->get_formatted_number();
    }

    But wc_gzdp_get_order_last_invoice($order) returns empty. Only after I try to Resend the order confirmation email manually, from the admin dropdown in the backend of the edit order page, does the conditional check pass and the formatted invoice number shows in the email that gets sent.

    I’ve also tried to use the Action Scheduler and send the order confirmation email after a 2-3 minutes delay once an order has been placed, but even then it’s the same result. The manual trigger I’m using after the delay is:

    WC()->mailer()->get_emails()['WC_Email_Customer_Processing_Order']->trigger($order_id);

    I’m not sure if I need to trigger some specific variation of the Germanized customer order confirmation email like WC_GZDP_Email_Customer_Order_Confirmation or use a different function than wc_gzdp_get_order_last_invoice($order) to be able to access and work with the invoice information inside the customer-processing-order.php template when the order is placed initially. Hoping you can please help me or give me some directions if you have an idea.

    Plugin Author vendidero

    (@vendidero)

    Hi there,

    the issue is that the actual invoice is only created when the get_attachments() method of the corresponding email is being called (which happens after the email has been rendered/content retrieved). That’s why your code won’t work. You could set the invoice automation settings to After checkout. Now you could use the following filter to make sure that the invoice is being attached to the customer_processing_order mail.

    add_filter( 'storeabill_woo_attach_invoice_to_email', function( $attach_to_mail, $email_id ) {
        if ( 'customer_processing_order' === $email_id ) {
            $attach_to_mail = true;
        }
        
        return $attach_to_mail;
    }, 10, 2 );

    Cheers

    Thread Starter mom4i911024

    (@mom4i911024)

    Hey, thank you. Would I be able to work with the invoice information inside the customer_processing_order mail by doing so?

    Currently my only issue is that i’m trying to access the invoice information inside the email but I can’t, as you’ve mentioned. Does that mean it’s not possible?

    Plugin Author vendidero

    (@vendidero)

    Yes, this way it’s possible. One issue still remains: By default the invoice will be created asynchronously via the Woo Action Scheduler (for the reasons I’ve already mentioned in my first post). You might prevent that from happening to retrieve the information from within the mail:

    add_filter( 'storeabill_woo_defer_auto_order_invoice_sync', '__return_false' );

    This way the invoice will be attached to the mail and you’ll be able to retrieve information right within the email template.

    Cheers

    Thread Starter mom4i911024

    (@mom4i911024)

    Awesome!! I’ve tried it now and by using these two filters together, alongside the After checkout setting, I’m able to work with the invoice information inside the email and I also get the PDF invoice attachment.
    Thank you so much!

    Plugin Author vendidero

    (@vendidero)

    Perfect, glad to help. If you enjoy our support and Germanized, we would be very happy to receive your review.

    Cheers

Viewing 7 replies - 1 through 7 (of 7 total)
  • The topic ‘Attach Invoice to order confirmation email’ is closed to new replies.