Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Add ability to save the pdf to wp-content/uploads #1

Open
wants to merge 7 commits into
base: master
Choose a base branch
from

Conversation

joldnl
Copy link

@joldnl joldnl commented Oct 17, 2019

For a client project I needed the cart pdf to be saved as an offer. So the client needs to have the pdf with the cart contents.

So I added some small functionality that saves the pdf to the wp-content/uploads/wc-cart-pdf folder.

This can be enabled with a new filter: 'wc_cart_pdf_save', which defaults to false, but can ben set to true to have it saved on disk.

Please let me know what you think of this.

Gr, Jurgen

@joldnl
Copy link
Author

joldnl commented Oct 17, 2019

I have added a custom action to execute before outputting the pdf. This is handy if you want to send an email with the pdf, or create a custom post or something.

@joldnl
Copy link
Author

joldnl commented Oct 17, 2019

En example of how to use the custom 'wc_cart_pdf_after_action' action:

// Send the cart-pdf to the site administrator email address
add_action( 'wc_cart_pdf_after_action', 'wc_cart_pdf_after_action', 10, 2 );
function wc_cart_pdf_after_action($uploads_folder, $filename) {

	$to = get_option('admin_email');
	$subject = 'Nieuwe Offerte';
	$message = 'Howdy Ho,<br><br>You have a new pdf: <a href="' . wp_upload_dir()['baseurl'] . '/wc-cart-pdf/' . $filename . '">' . $filename . '</a>';
	$headers = ['Content-Type: text/html; charset=UTF-8'];
	$attachments = $uploads_folder . $filename;

	wp_mail( $to, $subject, $message, $headers, $attachments );

}

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

1 participant