Last active
September 11, 2020 20:07
-
-
Save flymke/d16e850eb8d96e913caf84a6ddcb9040 to your computer and use it in GitHub Desktop.
WooCommerce Germanized Pro 2.1.6 - send packing slip via email
This file contains 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
/* | |
* 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