WordPress.org

Forums

WooCommerce PDF Invoices & Packing Slips
[resolved] Possible to send packing slip to an email adress I specify? (4 posts)

  1. Kainer
    Member
    Posted 1 year ago #

    I need to send the packing slip ONLY (NOT the invoice) to a specified email address. Possible with this plugin?

    https://wordpress.org/plugins/woocommerce-pdf-invoices-packing-slips/

  2. Ewout
    Member
    Plugin Author

    Posted 1 year ago #

    Hi Kainer,
    Do you want to do this automatically on an order status change or manually with a button?

    To do this automatically (this one is triggered on the completed status), you could try the following, handcrafted script:

    add_action("woocommerce_order_status_completed", "email_pdf_packing_slip", 10, 2);
    
    function email_pdf_packing_slip ( $order_id ) {
    	global $wpo_wcpdf;
    
    	// clear temp folder (from http://stackoverflow.com/a/13468943/1446634)
    	$tmp_path = WooCommerce_PDF_Invoices::$plugin_path . 'tmp/';
    	array_map('unlink', ( glob( $tmp_path.'*' ) ? glob( $tmp_path.'*' ) : array() ) );
    
    	// create pdf data
    	$packing_slip= $wpo_wcpdf->export->get_pdf( 'packing-slip', (array) $order_id );
    
    	$display_number = $wpo_wcpdf->export->get_display_number( $order_id );
    	$pdf_filename = __( 'packing-slip', 'wpo_wcpdf' ) . '-' . $display_number . '.pdf';
    	$pdf_path = $tmp_path . $pdf_filename;
    	file_put_contents ( $pdf_path, $packing_slip );
    	$attachments[] = $pdf_path;
    
    	// create mail data
    	$to			= 'person@mail.com';
    	$subject	= 'Packing Slip for order: ' . $display_number;
    	$headers	= 'From: Your name <your@mail.com>' . "\r\nContent-type: text/html\r\n";
    
    	// create mail body
    	ob_start();
    	?>
    	<html>
    	<head><title><?php echo $subject ?></title></head>
    	<body>
    		Here's an awesome packing slip!<br />
    		Cheers
    	</body>
    	</html>
    	<?php
    
    	$message = ob_get_clean();
    
    	// send the email!
    	wp_mail( $to, $subject, $message, $headers, $attachments );
    }

    I made this on my own install and it works, but since this is quite beyond the scope of the plugin, can't guarantee anything :o)

  3. Kainer
    Member
    Posted 1 year ago #

    Looks great, tghanks! How to make it include ONLY the invoice and NOT the packing slip?

    And is it possible to include customer name and lastname in the invoice?

  4. Ewout
    Member
    Plugin Author

    Posted 1 year ago #

    change:

    $packing_slip= $wpo_wcpdf->export->get_pdf( 'packing-slip', (array) $order_id );
    
    	$display_number = $wpo_wcpdf->export->get_display_number( $order_id );
    	$pdf_filename = __( 'packing-slip', 'wpo_wcpdf' ) . '-' . $display_number . '.pdf';
    	$pdf_path = $tmp_path . $pdf_filename;
    	file_put_contents ( $pdf_path, $packing_slip );

    to:

    $invoice= $wpo_wcpdf->export->get_pdf( 'invoice', (array) $order_id );
    
    	$display_number = $wpo_wcpdf->export->get_display_number( $order_id );
    	$pdf_filename = __( 'invoice', 'wpo_wcpdf' ) . '-' . $display_number . '.pdf';
    	$pdf_path = $tmp_path . $pdf_filename;
    	file_put_contents ( $pdf_path, $invoice );

    you can get more info on getting the last name here: Display "last name" in template. First name would be _billing_first_name.

Topic Closed

This topic has been closed to new replies.

About this Plugin

  • WooCommerce PDF Invoices & Packing Slips
  • Frequently Asked Questions
  • Support Threads
  • Reviews

About this Topic