Skip to content

Instantly share code, notes, and snippets.

@flymke
Last active September 11, 2020 20:07
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save flymke/d16e850eb8d96e913caf84a6ddcb9040 to your computer and use it in GitHub Desktop.
Save flymke/d16e850eb8d96e913caf84a6ddcb9040 to your computer and use it in GitHub Desktop.
WooCommerce Germanized Pro 2.1.6 - send packing slip via email
/*
* WooCommerce Germanized Pro 2.1.6
* Function to send packing slip via email
**/
function woocommerce_order_status_processing_callback($order_id) {
if ( ! $order_id ) {
return;
}
$order = new WC_Order( $order_id );
if ( function_exists( 'wc_gzd_get_shipments_by_order' ) ) {
$shipments = wc_gzd_get_shipments_by_order( $order );
if ( ! empty( $shipments ) ) {
// Use first shipment as fallback
$shipment = $shipments[0];
} else {
return false;
}
if ( $packing_slip = wc_gzdp_get_packing_slip_by_shipment( $shipment ) ) {
$to = 'user@example.com';
$headers = array();
$headers[] = 'From: Shop <shop@example.de>';
$attachments = array( $packing_slip->get_pdf_path() );
wp_mail( $to, 'Lieferschein zur Bestellung: '.$order->get_order_number.'', 'Der Lieferschein befindet sich im Anhang.', $headers, $attachments );
}
// add order note
$note = 'Der Lieferscheint wurde an ' . $to . ' gesendet.';
$order->add_order_note( $note );
}
}
add_action( 'woocommerce_order_status_processing', 'woocommerce_order_status_processing_callback');
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment