WordPress.org

Support

Support » Plugins and Hacks » [Resolved] Possible to send packing slip to an email adress I specify?

[Resolved] Possible to send packing slip to an email adress I specify?

Viewing 3 replies - 1 through 3 (of 3 total)
  • Plugin Author Ewout

    @pomegranate

    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)

    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?

    Plugin Author Ewout

    @pomegranate

    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.

Viewing 3 replies - 1 through 3 (of 3 total)
  • The topic ‘[Resolved] Possible to send packing slip to an email adress I specify?’ is closed to new replies.