Author Topic: Adding tracking numbers to orders and shipping confirmation emails  (Read 28395 times)

johnstep

  • Beginner
  • *
  • Posts: 12
Is there a way to automatically add shipping tracking numbers to an order and the customer's shipping confirmation email? I cannot find a way to automatically or even manually add it the to the order or confirmation emails.  ???

If so, which shipping modules (FedEx, UPS, USPS, etc) support this functionality?

IMHO, this seems like a very important feature that has been overlooked.

Any help or suggestions would be greatly appreciated...  :)

johnstep

  • Beginner
  • *
  • Posts: 12
Re: Adding tracking numbers to orders and shipping confirmation emails
« Reply #1 on: August 31, 2010, 22:15:41 pm »
I guess NO ONE cares about adding the tracking numbers to the orders or shipping confirmation emails.

Am I the ONLY person in the world the needs this functionality?

exlemor

  • Beginner
  • *
  • Posts: 1
Re: Adding tracking numbers to orders and shipping confirmation emails
« Reply #2 on: September 30, 2010, 02:31:24 am »
I definitely agree that this is needed functionality? did you ever figure out how?

Cheers,

Emmanuel.

kathyneptune

  • Beginner
  • *
  • Posts: 2
Re: Adding tracking numbers to orders and shipping confirmation emails
« Reply #3 on: October 07, 2010, 00:37:18 am »
John, I'm sure your not the only one who needs this functionality!  Try using a third-party software like Mailware to add tracking numbers to emails.  These kinds of softwares also include features like a multichannel manager and a back office system. 

kathyneptune

  • Beginner
  • *
  • Posts: 2
Re: Adding tracking numbers to orders and shipping confirmation emails
« Reply #4 on: October 07, 2010, 00:42:57 am »
John, I'm sure your not the only one who needs this functionality!  Try using a third-party software like Mailware to add tracking numbers to emails.  These kinds of softwares also include features like a multichannel manager and a back office system.  

nsrwholesale

  • Beginner
  • *
  • Posts: 12
Re: Adding tracking numbers to orders and shipping confirmation emails
« Reply #5 on: October 10, 2010, 01:51:43 am »
still no answer? anything inside virtuemart?

proman2008

  • Beginner
  • *
  • Posts: 35
Re: Adding tracking numbers to orders and shipping confirmation emails
« Reply #6 on: January 08, 2011, 23:43:37 pm »
also there should be a manual adding the tracking number to the order.


mrsjprice

  • Beginner
  • *
  • Posts: 20
Re: Adding tracking numbers to orders and shipping confirmation emails
« Reply #7 on: January 09, 2011, 00:41:17 am »
I need this as all my orders are sent out tracked. Me being able to provide my customers with a tracking number means I can give a better service.

Anyone?

Jeremy - CodeDonors.com

  • Beginner
  • *
  • Posts: 14
  • I recommend Joomla + VirtueMart
    • CodeDonors.com
  • Skype Name: jmcdonald.codedonors
Re: Adding tracking numbers to orders and shipping confirmation emails
« Reply #8 on: January 09, 2011, 05:05:59 am »
Hello,

I offer two modules called FedEx Complete for VirtueMart and UPS Complete for VirtueMart that provide rates, address validation, tracking and labels. On label creation creation the module automatically prints the label, sets the status to 'Shipped' and appends a message to the status e-mail that looks like this:
 
-----------------------------------------------------------------------
Your FedEx tracking number is: ###########

You can visit this link at any time to see the delivery status for your order:
http://www.fedex.com/Tracking?cntry_code=us&tracknumber_list=##########&language=english
-----------------------------------------------------------------------

The tracking feature of the module provides detailed start-to-finish tracking information within the order details screen like the following:

-----------------------------------------------------------------------

12/30/10 5:14 AM: Delivered - Corona CA
12/30/10 2:52 AM: On FedEx vehicle for delivery - ONTARIO CA
12/30/10 2:43 AM: At local FedEx facility - ONTARIO CA
12/30/10 12:10 AM: At dest sort facility - ONTARIO CA
12/29/10 10:44 PM: Departed FedEx location - MEMPHIS TN
12/29/10 8:33 PM: Arrived at FedEx location - MEMPHIS TN
12/29/10 6:49 PM: Departed FedEx location - NEWARK NJ
12/29/10 3:56 PM: Arrived at FedEx location - NEWARK NJ
12/29/10 3:30 PM: Left FedEx origin facility - MOONACHIE NJ
12/29/10 10:59 AM: Picked up - MOONACHIE NJ
12/28/10 10:27 AM: Shipment information sent to FedEx
-----------------------------------------------------------------------

Address validation reduces errors & return shipments, and our rates are guaranteed to match those of FedEx.com and UPS.com. There are a bunch of other features as well that make these modules well worth it.

Please feel free to contact me on Skype at jmcdonald.codedonors or via the forum. I am available to do live demos.
Been doing this for a long time and still having fun :-)

PHP, Javascript, CSS, Bash, Perl and Python

FYI...WebHostManager (WHM) offers free SSL for all sites on the server via Sectigo and you can turn it on in under 5 minutes.

mrsjprice

  • Beginner
  • *
  • Posts: 20
Re: Adding tracking numbers to orders and shipping confirmation emails
« Reply #9 on: January 09, 2011, 09:36:03 am »
I don't use those modules... I use the UK postcode one.

I need to be able o add tracking manually.

Minas

  • Beginner
  • *
  • Posts: 2
    • wsurf
Re: Adding tracking numbers to orders and shipping confirmation emails
« Reply #10 on: July 21, 2011, 00:34:28 am »
I need to be able o add tracking manually.

VM 1.1.8

Click on the order, go to 'Order Status Change" tab, include any comment like tracking no. , check 'include this comment' and update.. :)

Fariida

  • Beginner
  • *
  • Posts: 39
Re: Adding tracking numbers to orders and shipping confirmation emails
« Reply #11 on: September 01, 2011, 22:02:43 pm »
Hi,

I believe I've found a way, although a total hack, using javascript to add tracking numbers with a link in emails and to show them on the customers account. There is also a way to send the email as HTML. Its manually adding the tracking number but I think could save some time having to paste links all the time. I am currently using Virtuemart 1.1.9.

If you update your virtuemart you may have to add this all over again.

I am new to programming so if you have a better way or less code, by all means please post your ideas. Hopefully this will help to point some in the right direction.

This hack involves A LOT of steps, including messing around with your MySQL tables. Please BACKUP up your mysql database. Use this at your own risk! If this crashes your site I am not responsible to what happens if you choose to use this hack, but I've tried it out and so far nothing bad has happened, thus far, lol.

Summary of how it works
Basically New input boxes are added in the "order status change" tab to enter a tracking number and selecting the shipping carrier.

Once the tracking number is entered and the shipping carrier is selected, a code generates the tracking link with a message in the comments box instructing the customer where to go to track their package, just in case.

When the status update email is sent the customer with the tracking number and the link to track the package.

Customers can view their tracking number as a link to track the package, along with the shipping carrier used on their account page when they check the status of their orders.

How To:
Add Columns to MySQL table vm_order_history
Add 3 new fields (columns) at the end of you MySQL table "vm_order_history" (note the comments field is here)

You can name the fields whatever you choose but I used 
  • "tracking" - This is for the tracking number
  • "carrier" - for shipping carrier name such as UPS, USPS, FEDex etc...
  • "trackl" - Tracking number link - links to shipping carrier's site to look up tracking

Set all of the column properties as:
Type: Text
Collation: UTF8_General_CI
Attributes:
Null: YES (Check box)
Default: None
Extra:

Add Columns to MySQL table vm_orders
Add 4 new fields at the end of your MySQL Table "vm_orders". Use the same field (column) names you've used in the "vm_order_history" table. Later on you will have to instruct virtuemart to put this information in both tables, which i will show later.

(note whatever fields you put in the "vm_order_history" table you must put in the "vm_orders" table too if you want to display the information on the frontend user orders details page.)

  • "comments" - Remember the comments field from the "vm_order_history" table?
  • "tracking"
  • "carrier"
  • "trackl"

Set the column properties the same as before:
Type: Text
Collation: UTF8_General_CI
Attributes:
Null: YES (Check box)
Default: None
Extra:

That's all for the MySQL table.

Adding New Field Names
Now that you have your tables and fields set, open the ps_order.php file.
Location: administrator > components > com_virtuemart > classes > ps_order.php

(always make backups of your file when making changes)


Now we have to add the new field names from the MySQL tables
(this inserts the new tracking information entered from the "order status change" tab into "vm_order_history" and to update the "vm_orders" table from the "vm_order_history" table.)

Find:
Code: [Select]
$fields =array( 'order_status'=> $d["order_status"],
'mdate'=> $timestamp );
$db->buildQuery('UPDATE', '#__{vm}_orders', $fields, "WHERE order_id='" . $db->getEscaped($d["order_id"]) . "'");
$db->query();

// Update the Order History.
$fields = array( 'order_id' => $d["order_id"],
'order_status_code' => $d["order_status"],
'date_added' => $mysqlDatetime,
'customer_notified' => $notify_customer,
'comments' => $d['order_comment'],
);

$db->buildQuery('INSERT', '#__{vm}_order_history', $fields );
$db->query();

Change too:
Code: [Select]
$fields =array( 'order_status'=> $d["order_status"],
'tracking'=> $d["tracking"], //added for tracking number.
'carrier' => $d["carrier"], //added to show shipping carrier
'trackl'=> $d["trackl"], //added link for tracking the order
'mdate'=> $timestamp );
$db->buildQuery('UPDATE', '#__{vm}_orders', $fields, "WHERE order_id='" . $db->getEscaped($d["order_id"]) . "'");
$db->query();

// Update the Order History.
$fields = array( 'order_id' => $d["order_id"],
'order_status_code' => $d["order_status"],
'date_added' => $mysqlDatetime,
'customer_notified' => $notify_customer,
'comments' => $d['order_comment'],
'tracking' => $d['tracking'], //added for tracking number same name as input text name and id
'carrier' => $d['carrier'], //added to show shipping carrier same name as input text name and id
'trackl' => $d['trackl']  //added link for tracking the ordersame name as input text name and id
);

$db->buildQuery('INSERT', '#__{vm}_order_history', $fields );
$db->query();

For the new array names I've used the names given for the fields created in the MySQL database.


Adding text input boxes in "Order Status Change Tab" to add tracking number
This adds new input boxes to the order details page in the "order status change" tab. This information sends with the email if you've clicked "include this comment".

Open file
order.order.print.php
Location: administrator > components > com_virtuemart > classes > order.order.print.php

Change the form name to "trackingno" later we will use this to call some javascript to generate the link for us.

Find:
Code: [Select]
<form method="post" action="<?php echo $_SERVER['PHP_SELF'?>">

Change To:
Code: [Select]
<form id="example" name="example" method="post" action="<?php echo $_SERVER['PHP_SELF'?>">

Add two new rows in the table to the top of the comment box
Find the comment box:
Code: [Select]
<tr>
  <td class="labelcell" valign="top"><?php echo $VM_LANG->_('PHPSHOP_COMMENT') .":"?>
  </td>
<td>
<textarea id="order_comment" name="order_comment" rows="5" cols="25"></textarea>
                </td>
</tr>

Change to:
Code: [Select]
<tr>
             <td class="labelcell" valign="top">Tracking No.</td>
              <td><input type="text" value="" id="tracking" name="tracking"/> <!--enter tracking number here this number will show in the email and the order details on the front end -->
             
              </td>
              </tr>
  <tr>
    <td class="labelcell">Shipping Carrier</td>
    <td>
<select id="selector" name="selector">
                <option value="" selected></option>
                <option value=1>UPS</option>
                <option value=2>USPS</option>
 </select>
 <!--the id and name is the MySQL tables field name. these input field is hidden this is where the shipping carrier link will generated-->
  <input type="hidden" value="" id="trackl" name="trackl"/>
  <input type="hidden" value="" id="carrier" name="carrier"/>
 
        </td>
      </tr>
     </tr>
<tr>
  <td class="labelcell" valign="top"><?php echo $VM_LANG->_('PHPSHOP_COMMENT') .":"?>
  </td>
  <td>
<textarea id="order_comment" name="order_comment" rows="5" cols="25"></textarea>
                </td>

  </tr>

To show the tracking number in the "order history" tab in the same file order.order.print.php
Location: administrator > components > com_virtuemart > classes > order.order.print.php

Add "Tracking No." table header

Find:
Code: [Select]
<th><?php echo $VM_LANG->_('PHPSHOP_COMMENT'?></th>

Change to
Code: [Select]
<th><?php echo $VM_LANG->_('PHPSHOP_COMMENT'?></th>
                <th>Tracking No.</th><!--tracking number heading-->

Show tracking number in the new "Tracking No." column.

Find
Code: [Select]
echo "<td>".$order_event->comments."</td>\n";


Add Below
Code: [Select]
   echo "<td>".$order_event->tracking."</td>\n";

Once you update the tracking number it will now be shown in the order history tab.

Shipping Carrier and Link

Next we have to add the code to generate the tracking number according to the shipping carrier selected.

Find around line 60 of the order.order.print.php file:
Code: [Select]
<div style="float: right;">
  <span class="pagenav" style="font-weight: bold;">

copy and paste this javascript code above it
Code: [Select]
<script type="text/javascript">
    // Array Data for shipping links
var links = new Array();
links[1] = 'http://wwwapps.ups.com/WebTracking/track?HTMLVersion=5.0&loc=en_US&Requester=UPSHome&WBPM_lid=homepage%2Fct1.html_pnl_trk&trackNums='; //UPS tracking link
links[2] = 'http://trkcnfrm1.smi.usps.com/PTSInternetWeb/InterLabelInquiry.do?origTrackNum='; //USPS tracking link

//show shipping carrier
var carrier = new Array();
carrier[1] = 'UPS';
carrier[2] = 'USPS';

//which website the tracking number can be tracked
var info = new Array();
info[1] = 'Visit <a href="http://www.ups.com">UPS.com</a> to track your order.';
info[2] = 'Visit <a href="http://www.usps.com">USPS.com</a> to track your order.'
</script>

Note that in each array the number is the same for the shipping carrier so links[1], carrier [1], and info[1] all belong to the UPS shipping carrier. 

Generating Tracking Link and Comment
When the shipping carrier is selected from the dropdown box after entering the tracking number a link will be created using the link from the links array + tracking number entered

Add this code to the bottom of the order.order.print.php file:

Code: [Select]
  <script type="text/javascript">
        document.trackingno.selector.onchange = updateText;

        function updateText() {
          var obj_sel = document.example.selector;
          document.trackingno.trackl.value = links[obj_sel.value] + tracking.value; //takes the selected value and generates link according to the shipping carrier selected
    document.trackingno.carrier.value = carrier[obj_sel.value]
document.trackingno.order_comment.value = info[obj_sel.value]
}
    </script>

Example

If a USPS tracking number is 123456abcdef

and USPS is selected from the drop down the link generated will be:

http://wwwapps.ups.com/WebTracking/track?HTMLVersion=5.0&loc=en_US&Requester=UPSHome&WBPM_lid=homepage%2Fct1.html_pnl_trk&trackNums=123456abcdef

The comment box will fill with the message:
<a href="http://www.usps.com">USPS.com</a> to track your order.

(This message has html tags. I will show to how send this message without stripping HTML tags below.)

Showing The Tracking In Order Status Update Email

Enabling HTML code for order status Emails
Go back to the file ps_order.php
Location: administrator > components > com_virtuemart > classes > ps_order.php

Find Code :
Code: [Select]
$result = vmMail( $dbv->f("contact_email"),  $dbv->f("vendor_name"),
$db->f("user_email"), $mail_Subject, $mail_Body, '' );

Change Code To:
Code: [Select]
$headers = "Content-type: text/html\r\n"; //enables HTML in php emails

$result = vmMail( $dbv->f("contact_email"),  $dbv->f("vendor_name"),
$db->f("user_email"), $mail_Subject, $mail_Body, $headers, '' );


Order Status Email with Tracking Number and Link
Now we will add the new fields added from the arrays added earlier in the ps_order.php file, the ID to output the new tracking numbers will be:
Code: [Select]
$d['carrier'] //displays the shipping carrier. Shows information from the carrier field in the MySQL vm_order table
$d['tracking'] // tracking number Shows information from the tracking field in the MySQL vm_order table
$d['trackl'] // tracking link. Shows information from the trackl field in the MySQL vm_order table

Find under the comment // MAIL BODY
Code: [Select]
if( !empty($d['include_comment']) && !empty($d['order_comment'])

Tracking information will be sent if you've click "include this comment" in the order details page.

Add (within this "if" statement) the new information to be shown to the customer.

This is what I have but you may modify it how ever you want.
Code: [Select]
if( !empty($d['include_comment']) && !empty($d['order_comment']){
$message .= "Carrier: ";
$message .= $d['carrier']."<br/>";
$message .= "Tracking Number: ";
$message .= $d['tracking'];
$message .= "<br/><br/>";

$message .= $d['order_comment'];
$message .= "<hr/>";
$message .= "The number to track your package is ".$d['tracking']." Visit ".$d['trackl']." to track your shipment.";
}


Outputs:
Carrier: USPS
Tracking Number: 123456abcde

Visit USPS.com to track your order.

The number to track your package is 123456abcde Visit  http://wwwapps.ups.com/WebTracking/track?HTMLVersion=5.0&loc=en_US&Requester=UPSHome&WBPM_lid=homepage%2Fct1.html_pnl_trk&trackNums=123456abcdef to track your shipment

----
Notice when this email is received the html link code from the comment box and the <hr/> tag isn't stripped or shows as plain text.

Showing the Tracking Number With Link In the User's Order Information

We have to add the new MySQL field names to get the tracking number with a link and shipping carrier to show on the front end.

Find:
Code: [Select]
$listfields = 'o.order_id,o.cdate,order_total,o.order_status,order_currency,';


Change to:
Code: [Select]
$listfields = 'o.order_id,o.cdate,order_total,o.order_status,order_currency,tracking,carrier,trackl';
[/code

Next we want to add the new field names "tracking" "carrier" and "trackl" added in $listfields.
Find
[code]
$tmp_cell .= "<br /><strong>".$VM_LANG->_('PHPSHOP_ORDER_PRINT_PO_NUMBER').":</strong> " . sprintf("%08d", $db->f("order_id"));
[/code ]

Paste Below
[code]
$tmp_cell .= "<br/><strong>Tracking: </strong><a href=\"".$db->f("trackl")."\">".$db->f("tracking")."</a>";

$tmp_cell .= "<br/><strong>Shipping Carrier: </strong>".$db->f("carrier");

Outputs

Order Number: ##
Tracking: 123456abcdef
Shipping Carrier: USPS

(the link would be http://wwwapps.ups.com/WebTracking/track?HTMLVersion=5.0&loc=en_US&Requester=UPSHome&WBPM_lid=homepage%2Fct1.html_pnl_trk&trackNums=123456abcdef)


If anyone needs files i would be glad to upload them. Also if this does help you out let me know :-)

bcoelho

  • Beginner
  • *
  • Posts: 2
Re: Adding tracking numbers to orders and shipping confirmation emails
« Reply #12 on: November 01, 2011, 00:48:53 am »
Has any one tried Fariida's method?

I really appreciate what has been done, but I haven't been able to get it to work.

In the vm_order_history and vm_orders tables, only the tracking column shows data - the carrier and trackl columns are empty.

So the email only shows a tracking number - no carrier or tracking link.

Anybody have a suggestion?

Fariida, can you upload your order.order_print.php and ps_order.php files?

jasondapolito

  • Beginner
  • *
  • Posts: 1
Re: Adding tracking numbers to orders and shipping confirmation emails
« Reply #13 on: December 03, 2011, 16:06:55 pm »
Fariida - Thanks so much for this post, it was very helpful!!!! Saved me a bunch of time!

Got it working by changing the javascript in a few places. Added the onchange property directly to "selector" in the "example" form.  Also had to change the array index from 'obj_sel.value' to 'obj_sel.selectedIndex', and I may have copy pasted from Fariida's post incorrectly somewhere, but the form name for me was "example" not "trackingno".

VM1.1.6
Joomla 1.5.22

kvetka

  • Beginner
  • *
  • Posts: 9
    • Ooh-la-la-la Beadtique.com
Re: Adding tracking numbers to orders and shipping confirmation emails
« Reply #14 on: November 20, 2012, 05:50:12 am »
Hello again Fariida  :)

Thank you for this amazing hack. It is more complex than other hacks, but it is plausible to master if done step by step. I’m Canadian and I managed to customize the java script to Canada Post. It seems to work very well. I’m deeply grateful to you for sharing this information.

I’m using slightly older version of Virtumart than you Virtuemart 1.1.7, and I followed all the steps listed on here, and had no issue at all.

Having said that, there is one step that I need help with, and that is to Show The Tracking In Order Status Update Email
I’ve already enabled the html code, as you saw from my previous comments in the other forum. I’m having issues placing the following code within the “if” statement. I don’t understand what you exactly  mean?

This is the “if” statement:

Code: [Select]
if( !empty($d['include_comment']) && !empty($d['order_comment'])

This is the code I'm suppose to insert:

Code: [Select]
$message .= "Carrier: ";
$message .= $d['carrier']."<br/>";
$message .= "Tracking Number: ";
$message .= $d['tracking'];
$message .= "<br/><br/>";

$message .= $d['order_comment'];
$message .= "<hr/>";
$message .= "The number to track your package is ".$d['tracking']." Visit ".$d['trackl']." to track your shipment.";

Do I remove everything what is within the round brackets of the “if” statement, and replace it with the above code, or do I add it to the context that is already in the brackets?

Coding is so sensitive, if I miss a bracket, or semi colon, it won’t work. Would you mind showing me what is the whole code, including the "if" statement suppose to look like?


Much appreciated
Kvetka