Add Order Number to Invoice – osCommerce

By | October 1, 2010

A client wanted to add the order number to the invoice, so it shows like this;

It’s a pretty simple change, as shown below;

Remembering to also create the constant for the language;

Done!

Then I was asked to “pad” the Order Number with a bunch of leading zero’s. My first idea was to simply add in some zero’s like this;

Order Number: 000006

So the code would read;

[php]

00000

[/php]

But of course, this would not work as intended as there would always be 5 leading zeros, whereas it would look better to have 4 leading zeros in the 100’s and 3 leading zeros in the 1000’s – so….

000006
000066
000666
006666
and so on. By simply adding 5 leading zero’s I would get;

000006
0000066
00000666

etc. So, a quick look at the PHP site and I see that str_pad is the correct way to do this. Here’s the code;

[php]

[/php]

In this code I am saying that the Order Number ($oID) must be at least 6 digits long. If it less than 6 digits, then it is padded to the left (ie, preceeding the Order ID) with as many zeros as it takes to make the Order ID 6 digits. Hope that makes sense.

Anyway, I end up with exactly what is wanted! Which is always good.

2 thoughts on “Add Order Number to Invoice – osCommerce

  1. Chris

    Burt,
    Within which directory/php file are we making these edits?
    I would like to have my new store’s orders pick up where my previous website’s order numbers terminated.

  2. Chris

    Think I found it Burt.
    admin/invoice.php & includes/languages/english/invoice.php
    Now I just need a test purchase to see an invoice generated. 🙂

Leave a Reply

Your email address will not be published.