Forked from greathmaster/pmpro-add-pdf-invoice-attachment.php
Last active
October 22, 2021 08:08
-
-
Save andrewlimaza/e6a7f09125d2902c785b3af375ae0a93 to your computer and use it in GitHub Desktop.
Adds a PDF invoice attachment to checkout emails.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
<?php | |
/* | |
Add a PDF attachement of the invoice to the checkout email. This code gist must be configured... | |
1) Download the DOMPDF library: https://github.com/dompdf/dompdf | |
1.1) Save to wp-content/your-plugin/ | |
2) Download the PHP SVG library: https://github.com/PhenX/php-svg-lib | |
2.1) Save to dompdf/lib/ | |
3) Download the PHP FONT library: https://github.com/PhenX/php-font-lib | |
3.1) Save to dompdf/lib/ | |
Upon checkout, will create a folder (...wp-content/invoices/[user_name]/ and add a PDF invoice. The content is the exact copy of the email. | |
*/ | |
use Dompdf\Dompdf; | |
function my_init() | |
{ | |
include( dirname( __file__ ) . 'dompdf/autoload.inc.php' ); | |
global $dompdf; | |
$dompdf = new Dompdf(); | |
} | |
add_action('init', 'my_init'); | |
function my_pmpro_email_attachments($attachments, $email) | |
{ | |
global $dompdf; | |
//make sure it's a checkout email (but not the admin one) | |
if(strpos($email->template, "checkout_") !== false && strpos($email->template, "admin") === false) | |
{ | |
//make sure attachments is an array | |
if(is_array($attachments)) | |
$attachments = array(); | |
$dompdf->loadHtml($email->body); | |
$dompdf->render(); | |
$output = $dompdf->output(); | |
$user_login = $email->data['user_login']; | |
$upload_dir = wp_upload_dir(); | |
$user_dirname = $upload_dir['basedir'].'/invoices/'.$user_login; | |
if (!file_exists( $user_dirname )) | |
{ | |
wp_mkdir_p( $user_dirname ); | |
} | |
$date = date("Y-m-d"); | |
$path = $user_dirname."/invoice-".$date.".pdf"; | |
file_put_contents($path, $output); | |
//add our attachment | |
$attachments[] = $path; | |
} | |
return $attachments; | |
} | |
add_filter('pmpro_email_attachments', 'my_pmpro_email_attachments', 10, 2); |
Problem with the logo
pmpro-pdf-invoices {{logo_image}}
image not found or type unknown
Hi @dloignon
Sorry to hear about this issue, please can you reach out to https://yoohooplugins.com/support and we'll assist you further.
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
I have updated the code and it should fix the issue now.