image_pdfimage_print

Our WooCommerce plugin writes the tracking number into the order field tracking_number. It is possible that an order consists of several packages and that the tracking numbers are separated by commas in the field.

In addition, the carrierfield is used to enter the shipping service provider (e.g. DHL, DPD, etc.) with which the parcel was sent.

You can use the template customer-completed-order.phpto set the template for sending e-mails. Via the admin menu WooCommerce- > Settings- >E-Mails the template file can be adapted into the template and over it afterwards.

The tracking numbers could be displayed in the file e.g. above the footer, i.e. directly above:

/**
 * @hooked WC_Emails::email_footer() Output the email footer
 */
do_action( 'woocommerce_email_footer', $email );

The following code excerpt reads out the tracking numbers and shows them as DHL link in the e-mail. For production use, you would also have to read out the carrier at this point and put the link together accordingly depending on the carrier.

$post_id = $order->ID;
echo "tracking number for $post_id ";
$tn = get_post_meta($post_id, "tracking_number");
if ($tn) {
 $numbers = explode(',', $tn[0]);
 if ($numbers) {
 foreach ($numbers as $code) {
 echo '<a href="https://nolp.dhl.de/nextt-online-public/de/search?piececode="'.$code.'>'.$code.'</a><br/>';
 }
 }
}

/**
 * @hooked WC_Emails::email_footer() Output the email footer
 */
do_action( 'woocommerce_email_footer', $email );

 

Categories:

Comments are closed