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.