Cloning a Shipping Module

Building a new shipping module based on an existing one

You can create Shipping Modules easiest by cloning the closest matching Shipping Module to what you are trying to do.

As an example, we will consider the flat shipping module.

Shipping Modules have 2 parts:

The code file is located in:

The language file is located in:

To clone this module, for example, to flatfree.php you would copy the two flat.php files to flatfree.php

Note: Be sure the filename you choose does not have an underscore (_) in it.

Next, you need to change all occurrences of the strings flat and FLAT as follows:

flat flatfree

These identifiers are case sensitive.

These words are written separately or within the constants such as:

class flat {
$this->code = 'flat';


class flatfree {
$this->code = 'flatfree';

Once you have cloned the module then you can alter how it calculates shipping to the method that you need. This calculation is done in the quote() method.

Flat does not have complicated logic to compute a quote; it uses a single figure.

To see examples of quote calculations that are more complex, you might look at the items.php Shipping Module.

Cloning or creating a Shipping Module to function the way you need it is not too difficult if you just work through the steps on paper then recreate the same steps within the quote() function.

These forum threads might also give you ideas:

Still have questions? Use the Search box in the upper right, or try the full list of FAQs. If you can't find it there, head over to the Zen Cart support forum and ask there in the appropriate subforum. In your post, please include your Zen Cart and PHP versions, and a link to your site.

Is there an error or omission on this page? Please post to General Questions on the support forum. Or, if you'd like to open a pull request, just review the guidelines and get started. You can even PR right here.
Last modified September 13, 2020 by Scott C Wilson (354bf51).