• Resolved borish1

    (@borish1)


    Hi,

    Current setup is this:

    User orders something from the shop and on the thank you page invoice gets sent to the user and to the third party service as well.

    What I want to do is to:
    1. send invoice using template v1 to the user
    2. Send invoice using template v2 to the third party service.

    I have everything written regarding the functionalities but I cannot find any functions related to changing the template. Is this achievable in any way with one of your functions from the plugin? I don’t need any code writeup, I just need you to direct me in which files to look. I can inspect it and figure out.

    If this is not possible can I then somehow use the wcpdf_after_document hook and include the necessary additional page on the first email and then remove it on the second email?

    Thanks a lot and keep up the great work with this plugin.

    • This topic was modified 4 years, 8 months ago by borish1.
Viewing 5 replies - 1 through 5 (of 5 total)
  • Plugin Contributor alexmigf

    (@alexmigf)

    Hello @borish1

    What are the differences between the two templates that you want to setup?

    Thread Starter borish1

    (@borish1)

    Key difference is an additional page so if you look at it I could be using the same template but then I need to figure out a way to include that additional page in the template for third party service while giving the default one without it to the customers.

    Plugin Contributor alexmigf

    (@alexmigf)

    Hello @borish1

    I believe that the easy way to do this is with our Professional extension, because you can attach static files to emails. That way you can use the default customer email to send the PDF invoice to the client and use the plugin Order Notification email to send the invoice to the third-party service with the static file attached too.

    Unless you send a manual email to the third-party service, I’m not seeing another way to do it.

    Let me know.

    Thread Starter borish1

    (@borish1)

    Hey @alexmigf,

    First of all, thank you for the fast response, appreciate it. I’ve taken your proposition as a last resort but I managed to work it out.

    I’ll give it a sort of explanation in case someone finds this useful.

    I modified the existing simple template of the plugin by adding an additional page that I need to send to the third-party service. I’m doing some checkups there before I load that second page. To be more exact I have a custom field that is used to check if the woo emails are sent. At the first check, they are not so at that time I included that second page. (simple true/false field). I’m hooking in one of the “after_woo_email_sent” hooks (can’t remember the name and saving the field.

    Then I hook into woocommerce_checkout_order_processed and do the API connection/sending of the PDF. Before I send the actual PDF what I do is, instead of just looking for the existing generated PDF I put the existing data that we can get through get_pdf() into already predefined $path.

    `$invoice = wcpdf_get_invoice($order, true);
    $pdf_data = $invoice->get_pdf();
    $tmp_path = WPO_WCPDF()->main->get_tmp_path(‘attachments’);
    $filename = $invoice->get_filename();
    $pdf_path = $tmp_path . $filename;
    file_put_contents($pdf_path, $pdf_data);
    return realpath($pdf_path);`

    Now, here the main problem was that I would get that same generated PDF 2 pager sent to customers but then I found 2 actions inside your plugin.
    First one being wpo_wcpdf_email_attachment where I regenerate the existing PDF.

    add_action("wpo_wcpdf_email_attachment","cr_regenerate_pdf",10,3);
    
    function cr_regenerate_pdf($pdf_path, $document_type, $document) {
        $pdf_path = get_pdf_path($document->order);
    }

    Now I also found that I need to lower the time at which the plugin will “let” user regenerate the file by using wpo_wcpdf_reuse_attachment_age and lowering it to 1 second since both emails are being sent 1 after another. Otherwise plugins locks the file and that was the main reason I couldn’t regenerate it instantly without using this filter.

    add_filter("wpo_wcpdf_reuse_attachment_age","cr_min");
    function cr_min() {
        return 1;
    }

    After that API sends the regenerated PDF which is 1 pager this time to the customer.

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

    (@alexmigf)

    Hi @borish1

    Glad you found a solution that works for you ??

    Have a great day!

Viewing 5 replies - 1 through 5 (of 5 total)
  • The topic ‘Use different template for specific sendings’ is closed to new replies.