Most ERPs suitable for WooCommerce allow store owners to manage orders conveniently and do not support customers to query tracking information without logging in. For example, Shopkeeper ERP can easily manage orders, and there is no separate page for customers to Query the logistics status of the order. In this article, you can learn quickly create a Track My Order shortcode and use the order ID and email to query the shipping provider name and the tracking number of the order.
To create a shortcode without modifying the original theme for your store, you have to create a child theme for the current theme. Now in the functions.php
file and add the code below.
add_shortcode('track_my_order', 'track_my_order_function');
function track_my_order_function()
{
ob_start();
?>
<div class="check-order-tracking">
<form action="" method="post">
<div class="form-group">
<label for="order_id">Order ID</label>
<input type="text" name="order_id" id="order_id" class="form-control" placeholder="Enter Order ID" required value="<?php echo $_POST['order_id']; ?>">
</div>
<div class="form-group">
<label for="order_email">Email</label>
<input type="email" name="order_email" id="order_email" class="form-control" placeholder="Enter Email" required value="<?php echo $_POST['order_email']; ?>">
</div>
<div class="form-group text-center">
<button type="submit" class="button success expand">Track Now</button>
</div>
</form>
</div>
<?php
if (isset($_POST['order_id']) && isset($_POST['order_email'])) {
$order_id = $_POST['order_id'];
$order_email = $_POST['order_email'];
$order = wc_get_order($order_id);
if ($order) {
$order_data = $order->get_data();
$billing_email = $order_data['billing']['email'];
$provider_name = $order->get_meta('_dianxiaomi_tracking_provider_name');
if ($order_email == $billing_email) {
if ($provider_name) {
$tracking_number = $order->get_meta('_dianxiaomi_tracking_number');
echo '<div class="success" style="padding: 10px; color: white;border-radius: 5px;" role="alert">Your order is shipped by ' . $provider_name . ' with tracking number <a target="_blank" style="color:white; font-weight: bold;" href="https://t.17track.net/en#nums=' . $tracking_number . '">' . $tracking_number . '</a>.</div>';
} else {
echo '<div class="alert" style="padding: 10px; color: white;border-radius: 5px;" role="alert">Your order is not shipped yet.</div>';
}
} else {
echo '<div class="alert alert-danger" style="padding: 10px; color: white;border-radius: 5px;" role="alert">Your order id or email is not correct.</div>';
}
} else {
echo '<div class="alert alert-danger" style="padding: 10px; color: white;border-radius: 5px;" role="alert">Your order id or email is not correct.</div>';
}
}
return ob_get_clean();
}
Now you can use the shortcode [track_my_order]
in any page or post of your store. After submitting the correct order ID and Email, the tracking provider name and the tracking number will be shown below the check now button. When clicking on the tracking number, it will jump to the 17tracking website for more details.
The code above works with the WooCommerce store on any theme if you’re using Dianxiaomi ERP to manage the WooCommerce orders.
Attention all e-commerce business owners and bloggers, we're excited to introduce the latest WordPress plugin…
Keeping track of orders across multiple WooCommerce stores can be a hassle, but with WooCat…
Are you looking for an easy way to manage your WooCommerce stores? Look no further…
After several times of reviewing by the WordPress Team, Auto Bulb Finder for WordPress &…
In this update, the Store Only feature is brought to the Auto Bulb Finder Plugin.…
Search Similar Bulb Size New Features You can easily search the similar bulb size name…
This website uses cookies.