Contact Information in PDF footer?
-
Hello, is there a means to include contact information in the footer of the PDF that is generated? Also, I think someone has mentioned this before, but is there a means for an admin to get an email with the pdf and cart information as well?
-
Hello
To add to the footer, first copy the PDF template from the plugin folder wc-cart-pdf/templates/cart-table.php into your child theme folder child-theme/woocommerce/wc-cart-pdf/cart-table.php
From there you can modify the PDF template and add your footer.
To send an email, you can use this hook to trigger the email being sent
do_action( 'wc_cart_pdf_output', $mpdf );
The
$mpdf
parameter is the mPDF object you can use to save the PDF somewhere or send it as an attachment in the emailThanks! I believe I figured out the footer, and have that implemented. However, I haven’t had much experience with software development. Could someone provide an example of using the do_action mentioned above to send an email with the pdf to the admin or other specified email?
Also, is there a means to display what product options were selected for products in the cart? In my instance, I’m using the Advanced Product Fields plugin that allows me to create custom fields for each product, from which users can select available options. So, as an example, you might have a “Color” option, a “Size” option and a “material” option, and each option choice has a different cost added. So, how would I include these option in the pdf?
I don’t mean to be a nuisance, I just trying to find out what options I have available to achieve a solution I’m looking for.
UPDATE: I think I’ve figured this part out. There was an option in Advanced Product Fields to enable selected options to be shown in cart, and this plugin pulled in those options into the pdf!
- This reply was modified 3 years, 10 months ago by raymc.
I apologize for this code, it’s embarrassingly bad. Again, I’m NOT a programmer!
It “partially” works. If I include both the add_action, and the do_action in functions.php, it will at least send an e-mail, but it doesn’t have the attachment. It’s just a plain email with the message body specified below. Where and how do I trigger it properly and by what means can I attach the generated pdf.
// START Email Pdf code – this is in functions.php, but should it be?
add_action(‘wc_cart_pdf_output’, ‘my_pdf_mail_function’, 10, 1);
function my_pdf_mail_function($mpdf) {
$to = ‘[email protected]’;
$subject = ‘Test Email’;
$body = ‘Testing out sending this’;
$headers = array(‘Content-Type: text/html; charset=UTF-8′,’From: [email protected]’);
$attachments = $mpdf;
wp_mail( $to, $subject, $body, $headers, $attachments );
}// END Email Pdf code
// Where does this go?
do_action( ‘wc_cart_pdf_output’, $mpdf );Please try something like this,
add_action( 'wc_cart_pdf_output', function( $mpdf ) { $file_path = get_temp_dir() . 'WC_Cart-' . date( 'Ymd' ) . bin2hex( openssl_random_pseudo_bytes( 5 ) ) . '.pdf'; $mpdf->Output( $file_path, 'F' ); wp_mail( '[email protected]', 'Subject', 'Body', '', [ $file_path ] ); unlink( $file_path ); } );
This saves the PDF to a temp directory before sending the email, and then removes the PDF from the filesystem after email is sent.
YES, thank you, I have it working now. You’ve been very gracious in your help!
However, is there a means to collect the users contact information and send that as well? Something simple, like name, email, phone and company? I think someone else had asked this question also, a couple of months ago.
Thanks again!
This has been something others have requested. It is possible to do with programming currently, but I plan on implementing this feature in the coming weeks if you can hang tight.
I just added the contact information to the PDF. It is only able to gather that information if the user generating the PDF is logged in.
There is also an option now to send the PDF via email, and in the body of the email the users contact information will also display there
Navigate to Appearance > Customize > WooCommerce > Cart PDF and you can enable this feature.
Thanks for the updates, however, now there appear to be a conflict with another plugin that I use for gravity forms, called gravity pdf. I didn’t realize until just now. Is there way to fix this, here is the error:
Fatal error: Uncaught Mpdf\MpdfException: Cannot find TTF TrueType font file “DejaVuSans.ttf” in configured font directories. in /home/regencyinteracti/ladybug.regencyinteractive.net/wp-content/plugins/gravity-forms-pdf-extended/vendor/mpdf/mpdf/src/Fonts/FontFileFinder.php:33 Stack trace: #0 /home/regencyinteracti/ladybug.regencyinteractive.net/wp-content/plugins/gravity-forms-pdf-extended/vendor/mpdf/mpdf/src/Mpdf.php(3861): Mpdf\Fonts\FontFileFinder->findFontFile(‘DejaVuSans.ttf’) #1 /home/regencyinteracti/ladybug.regencyinteractive.net/wp-content/plugins/gravity-forms-pdf-extended/vendor/mpdf/mpdf/src/Mpdf.php(4154): Mpdf\Mpdf->AddFont(‘dejavusans’, ”) #2 /home/regencyinteracti/ladybug.regencyinteractive.net/wp-content/plugins/gravity-forms-pdf-extended/vendor/mpdf/mpdf/src/Mpdf.php(10875): Mpdf\Mpdf->SetFont(‘dejavusans’) #3 /home/regencyinteracti/ladybug.regencyinteractive.net/wp-content/plugins/gravity-forms-pdf-extended/vendor/mpdf/mpdf/src/Mpdf.php(1483): Mpdf\Mpdf->SetDefaultFont(‘dejavusans’) #4 /home/regencyi in /home/regencyinteracti/ladybug.regencyinteractive.net/wp-content/plugins/gravity-forms-pdf-extended/vendor/mpdf/mpdf/src/Fonts/FontFileFinder.php on line 33
Can you email me at [email protected] and I’ll look into this for you and get it resolved
THANKS, AND SENT!
- The topic ‘Contact Information in PDF footer?’ is closed to new replies.