What can we help you with?
Get DHL Tracking Numbers for WooCommerce Order IDs (Code Snippet)
By default, the ELEX WooCommerce DHl Shipping Plugin shows tracking status in a pop-up window. If you wish to display DHL tracking numbers in desired pages of your website, you can follow the steps mentioned in this article.
This code snippet will only for ELEX WooCommerce DHL Shipping Plugin.
Code snippet to get DHL Tracking Numbers
Step 1: Add the following code snippet at the end of the functions.php file of your activate website theme.
/*Shortcode to get DHL tracking numbers (AirWay Bill Numbers) for provided WooCommerce Order id */ add_shortcode('ELEX_DHL_TRACK_INFO', 'get_tracking_numbers_express_dhl_elex'); function get_tracking_numbers_express_dhl_elex($attributes){ if(!isset($attributes['order_id'])) return; $airway_bill_numbers = get_post_meta($attributes['order_id'], 'archive_reference_data_dhl_elex', true); $tracking_number = ''; if(!empty($airway_bill_numbers)){ $tracking_number = $airway_bill_numbers['airway bill number']; } return $tracking_number; }
Step 2: Use the shortcode [ELEX_DHL_TRACK_INFO order_id=”{woocommerce order id}”] in any of the desired pages to display the tracking status. You should replace {woocommerce order id} with your desired order ID.
Let us understand this with a simple demonstration.
We can add the shortcode [ELEX_DHL_TRACK_INFO order_id=”4491″] in the My-Accounts page, as shown in the screenshot below.
You can customize how the tracking number has to be displayed as you like. Once you save the settings of the page, you can move to the My-Accounts page to see the DHL Tracking Number, as shown in the sample screenshot below.
In this way, you can the tracking number in any of the desired page(s).
To explore more details about the plugins, go check out ELEX WooCommerce DHL Express / eCommerce / Paket Shipping Plugin with Print Label.
Read the article for setting up DHL Express understand the plugin, in detail. Or check out the product documentation section for more related articles.
You can also check out other WooCommerce and WordPress plugins in ELEX.