Attachment DHL Label in email Lieferschein

<?php
add_filter('storeabill_packing_slip_email_summary_fields', 'tzn_custom_storeabill_shipment_email_summary_fields', 99, 99);
function tzn_custom_storeabill_shipment_email_summary_fields($fields, $sent_to_admin, $document)
{
    if ($document->get_shipment_id()) {
        $shipment_id = $document->get_shipment_id();
        $shipment = wc_gzd_get_shipment($shipment_id);
        if ($shipment) {
            $tracking_id = $shipment->get_tracking_id();
            $fields[] = array(
                'label' => __('DHL Label', 'tzn'),
                'value' => $tracking_id
            );
        }

    }
    return $fields;
}
add_filter('woocommerce_email_attachments', 'tzn_custom_woocommerce_email_attachments', 10, 4);
function tzn_custom_woocommerce_email_attachments($attachments, $email_id, $object, $objects = false)
{
    if ($email_id == "sab_packing_slip") {
        // sleep(160);
        if ( $order_shipment = wc_gzd_get_shipment_order( $object->get_order_number() ) ) {
            $order_shipment_id = $order_shipment->get_order()->get_order_number();
            foreach (wc_gzd_get_shipments_by_order($order_shipment_id) as $shipment) {
                if ($shipment && $shipment->has_label()) {
                    $label = $shipment->get_label();
                    if ($file = $label->get_file()) {
                        $attachments[] = $file;
                    }
                }
            }
        }
    }
    return $attachments;
}
?>

/Plugin/woocommerce-germanized-pro/src/StoreaBill/PackingSlips.php

Leave a Reply

Your email address will not be published. Required fields are marked *