the_lyall
Active Member
I’ve seen a few different posts about this while searching for a solution myself so I’ve made my own solution and thought I’d share it here.
There are a few reasons why I wanted to use Cainiao rather than 17Track:
For example, you can use a tracking link like this: https://ecorelos.com/order-tracking/?LN844243263CN
You will notice that I’ve cropped the tracking after the most recent events and that is deliberate. If you leave enough space (on desktop view only) the page will add a footer section which includes links to AliExpress etc. which I don’t want. If you crop the frame the page doesn’t add the footer as it won’t fit in the frame. On mobile view it doesn’t show anyway.
STEPS:
In WooCommerce go to Pages > Add New and create a page called something logical. I used ‘Order Tracking’ but you can use anything you want.
That’s all for now. If you have any SEO or XML Sitemap plugins, update those settings so that this new page isn’t indexed as you don’t want it to be crawled.
Give it a name – I called mine ‘TrackingFrame’ but you can call it anything.
For the content, add the following:
Explanation:
class="trackingframe" gives the frame a CSS class so you can target it with CSS later
src="https://global.cainiao.com/detail.htm?mailNoList= is the URL of the tracking page to use, minus the tracking number. You can use any carrier tracking link here
<?php echo $_SERVER['QUERY_STRING']; ?> is the PHP code which takes whatever query string is in the current page URL (i.e. whatever is after a question mark like google.com?1234 would mean ‘1234’ is the query string) and adds it to the iframe URL.
width="100%" frameborder="0" scrolling="no" are iframe attributes to make the frame full width, without a border and non-scrollable.
Save the snippet and the plugin will show you the shortcode you can use to add that snippet to a page (in my case [xyz-ips snippet="TrackingFrame"]).
Now when you visit that page, the iframe will look at the page URL and copy the query string. So if you add a query string such as tracking.com/mypage?CN1234 the iframe URL would be https://global.cainiao.com/detail.htm?mailNoList=CN1234.
If you access the page directly (without a query string) it will show the Cainiao error/no tracking page. Therefore I don’t have the page accessible through the front end, only via the My Account tracking links and the email tracking links.
Without this part, the page will work but will be Cainaio branded. My CSS is below as an example:
The height of the header is 80px on desktop and 50px on mobile, so use CSS media queries to target smaller screens separately.
That's all!
There are a few reasons why I wanted to use Cainiao rather than 17Track:
- 17Track includes ads on the page which show on your site if you use an iframe.
- The Cainiao tracking details are more accurate, detailed, recent and easier to understand (in my experience). It also has (on desktop) the nice progress animation at the top.
- If you or your customer Googles '17Track' it brings up a lot of negative reviews saying that it's a scam. Obviously just because 17Track is used by scammers doesn't mean it's a scam itself, but the negative reviews can lower customer confidence in your own site.
For example, you can use a tracking link like this: https://ecorelos.com/order-tracking/?LN844243263CN
You will notice that I’ve cropped the tracking after the most recent events and that is deliberate. If you leave enough space (on desktop view only) the page will add a footer section which includes links to AliExpress etc. which I don’t want. If you crop the frame the page doesn’t add the footer as it won’t fit in the frame. On mobile view it doesn’t show anyway.
STEPS:
- Create a tracking page
- Create the dynamic iframe link (works with any carrier)
- Add the link to the page
- Update the plugin tracking setting
- Add CSS
- Create a tracking page
In WooCommerce go to Pages > Add New and create a page called something logical. I used ‘Order Tracking’ but you can use anything you want.
That’s all for now. If you have any SEO or XML Sitemap plugins, update those settings so that this new page isn’t indexed as you don’t want it to be crawled.
- Create the dynamic iframe link
Give it a name – I called mine ‘TrackingFrame’ but you can call it anything.
For the content, add the following:
HTML:
<iframe class="trackingframe" src="https://global.cainiao.com/detail.htm?mailNoList=<?php echo $_SERVER['QUERY_STRING']; ?>" width="100%" frameborder="0" scrolling="no">
Explanation:
class="trackingframe" gives the frame a CSS class so you can target it with CSS later
src="https://global.cainiao.com/detail.htm?mailNoList= is the URL of the tracking page to use, minus the tracking number. You can use any carrier tracking link here
<?php echo $_SERVER['QUERY_STRING']; ?> is the PHP code which takes whatever query string is in the current page URL (i.e. whatever is after a question mark like google.com?1234 would mean ‘1234’ is the query string) and adds it to the iframe URL.
width="100%" frameborder="0" scrolling="no" are iframe attributes to make the frame full width, without a border and non-scrollable.
Save the snippet and the plugin will show you the shortcode you can use to add that snippet to a page (in my case [xyz-ips snippet="TrackingFrame"]).
- Add the link to the page
Now when you visit that page, the iframe will look at the page URL and copy the query string. So if you add a query string such as tracking.com/mypage?CN1234 the iframe URL would be https://global.cainiao.com/detail.htm?mailNoList=CN1234.
If you access the page directly (without a query string) it will show the Cainiao error/no tracking page. Therefore I don’t have the page accessible through the front end, only via the My Account tracking links and the email tracking links.
- Update the plugin tracking setting
- Add CSS
Without this part, the page will work but will be Cainaio branded. My CSS is below as an example:
CSS:
.trackingframe{
margin-top:-80px; //move it up 80px to hide the header
height:100%;
width:100%;
z-index:-1; //make it go under the header instead of over it
overflow-x:hidden; //hide the horizontal scrollbar
min-height:585px; //set the height that I want to show
}
The height of the header is 80px on desktop and 50px on mobile, so use CSS media queries to target smaller screens separately.
That's all!
Last edited: