Skip to content

Instantly share code, notes, and snippets.

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 hamzahjamad/902bc56e438247558f8c6cd8b5249c7c to your computer and use it in GitHub Desktop.
Save hamzahjamad/902bc56e438247558f8c6cd8b5249c7c to your computer and use it in GitHub Desktop.
Add tracking.my shippment tracking number to woocommerce email order
<?php
// The plugin: https://www.tracking.my/integration/woocommerce
//
// To integrate tracking.my shipment tracking number to woocomerce order email
// add below function to functions.php
// Tracking.my add tracking number to email
function add_tracking_info_to_order_email( $order, $sent_to_admin, $plain_text, $email ) {
// Get the order ID
$order_id = $order->get_id();
// Retrieve the _shipment_trackings_trackingmy meta field
$tracking_items = get_post_meta( $order_id, '_shipment_trackings_trackingmy', true );
// Check if tracking items exist
if ( $tracking_items && is_array( $tracking_items ) ) {
echo '<h2>Shipment Tracking Information:</h2>';
// Loop through tracking items and display information
foreach ( $tracking_items as $tracking_item ) {
echo '<p>';
echo '<span style="font-weight: bold;">Tracking Number:</span> ';
echo '<a href="' . esc_url( $tracking_item['short_link'] ) . '">';
echo esc_html( $tracking_item['tracking_number'] );
echo '</a>';
echo '</p>';
// For full details, use code below
//echo '<p>Order ID: ' . esc_html( $tracking_item['order_id'] ) . '</p>';
//echo '<p>Short Link: <a href="' . esc_url( $tracking_item['short_link'] ) . '">' . esc_html( $tracking_item['short_link'] ) . '</a></p>';
//echo '<p>Tracking ID: ' . esc_html( $tracking_item['tracking_id'] ) . '</p>';
//echo '<p>Tracking Number: ' . esc_html( $tracking_item['tracking_number'] ) . '</p>';
//echo '<p>Courier: ' . esc_html( $tracking_item['courier'] ) . '</p>';
//echo '<p>Note: ' . esc_html( $tracking_item['note'] ) . '</p>';
//echo '<p>Parcel Content: ' . esc_html( $tracking_item['parcel_content'] ) . '</p>';
//echo '<p>Status: ' . esc_html( $tracking_item['status'] ) . '</p>';
}
}
}
add_action( 'woocommerce_email_after_order_table', 'add_tracking_info_to_order_email', 10, 4 );
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment