I use e2pdf shortcode into woocommerce emails additionnal content box to generate pdf attachments.
It works well. I would like to store the pdf as well. I tried some shortcodes without result. Can you help please?
Here is my last try:
[e2pdf-save id="16" attachment="true" dir="wp-content/uploads/testdevispdf/]
The pdf is attached to the email, but not saved.
Regards
29 April, 2024 01:03:23
E2Pdf
Support
Topics: 7
Messages: 3574
Hello,
Please, recheck:
1. Be sure that all attributes are closed correctly:
* You can get the absolute path by enabling debug mode at "E2Pdf" -> "Settings" and checking the "E2Pdf" -> "Debug" page.
29 April, 2024 02:17:44
eliodata
Topics: 19
Messages: 57
Thank you for the quick answer!
The attribute was unclosed... sorry for that.
Do you think it is possible to dynamically create the folder? I tried this:
function generate_pdf_on_status_change($order_id, $old_status, $new_status, $order) {
$user_info = get_userdata($order->get_user_id());
$username = $user_info->user_login; // Récupère le nom d'utilisateur de WordPress
// Assurez-vous que le répertoire existe
if (!file_exists($pdf_dir)) {
wp_mkdir_p($pdf_dir);
}
// Mettez ici le code pour générer le PDF
// Vous pouvez utiliser e2pdf avec quelque chose comme ça :
echo do_shortcode('[e2pdf-save id="1" dir="' . $pdf_dir . '" create_dir="true" create_index="true"]');
}
the path is well created and the pdf attached to the email. But it isn't saved into the created folder.
It was added "dataset" and "apply" attributes. It's required in case called from PHP. We suppose your E2Pf has a connection to "WooCommerce" -> "Orders".
It has been removed The function that creates a folder, as when it is used "create_dir" - E2Pdf will check and create it if it does not exist.
30 April, 2024 06:01:14
eliodata
Topics: 19
Messages: 57
Thank you!
I don't use woocommerce > orders
Just paste the shortcode into the email additionnal content box.
Should I paste the shortcode from your code instead?
30 April, 2024 06:11:32
E2Pdf
Support
Topics: 7
Messages: 3574
Can you let us know please the connection of the E2Pdf Template? It requires setting the correct "dataset" attribute when the shortcode is called from PHP.
1 May, 2024 05:11:32
eliodata
Topics: 19
Messages: 57
Ok sorry I thought you were talking about the e2pdf settings options. It is a "orders" template yes.
1 May, 2024 05:13:43
E2Pdf
Support
Topics: 7
Messages: 3574
Then yes, the updated code should work. If still not, let us know please, and we will do additional checks.
1 May, 2024 06:12:28
eliodata
Topics: 19
Messages: 57
Still nothing sorry. Maybe I'm doing something wrong.
Here the working code to create the correct path: https://codefile.io/f/18yqusmwxT
But it doesn't save the pdf into the file.
and
[e2pdf-save id="16" attachment="true" dir="wp-content/uploads/testdevispdf/"]
Works great to save the pdf.
thank you again
1 May, 2024 06:26:22
E2Pdf
Support
Topics: 7
Messages: 3574
You are missing the "dataset" and "apply" attributes in your PHP snippet, as it's mandatory when shortcode is called from PHP:
We use cookies to collect and analyse information on site performance and usage, to provide social media features and to enhance and customise content and advertisements. By clicking "Accept Selected", you consent to use of selected cookies according our to our Cookie Policy.