Shipping Plugins
CartThrob has a shipping plugin interface, and several helper functions that simplify the creation of shipping plugins. Refer to one of the included shipping plugins as an example. The “Flat Rates” plugin uses most of the functionality available to ur shipping plugins, so it’s a good starter example of what’s possible.
Overview
By default, sessions data is automatically available for all shipping plugins you create, so you do not have to start a session for your plugin, or plugin functions. Also, there are several helper functions available for grabbing data from the customer’s current cart, and functions available for communicating with offsite shipping systems.
Plugin Info
'title' => 'Flat Rates 2', 'classname' => 'Cartthrob_flat_rates_2', // needs to be the same as the file's classname 'affiliate' => 'No affiliate link set yet, move along', 'overview' => 'This payment system requires you to go to the following URL and sign up, etc, etc',
These fields, located at the top of the plugin allow you to set some general information about your plugin. Title and Classname are required. The rest are optional.
Plugin Settings
'settings' => array( array( 'name' => 'Settings Example', // descriptive name 'short_name' => 'settings_example', // you will use this to access this setting your code. 'type' => 'text', // or textarea 'default' => 'Whatevs', // optional ), array( 'name' => 'Settings Example 2', 'short_name' => 'settings_example_2', 'type' => 'radio', 'default' => 'yes', 'options' => array( 'yes' => 'Yes', 'no' => 'No', ), ), array( 'name' => 'Settings Example 4', 'short_name' => 'settings_example4', 'type' => 'matrix', 'settings' => array( array( 'name' => 'Matrix Settings?', 'short_name' => 'matrix_settings', 'type' => 'checkbox', 'options' => array( 'they_work' => 'Yep' ) ), ), )
Using the “settings” array, you can create multiple setting fields that will display in the plugin’s settings when it is selected. Name, short_name, and type are required for each settings group. You may optionally provide a default value. The available types include “text”, “textarea”, “radio”, “checkbox” and “matrix”. Find examples of each are shown above.
Get_shipping function
The get_shipping function is the only required function in your shipping plugin.
function get_shipping()
Helper Functions
shipping_weight_total
$weight = $this->shipping_weight_total()
This returns the combined weight of all of the items in the cart
shipping_cart_subtotal
$weight = $this->shipping_cart_subtotal()
This returns the cost of the items in the cart without shipping or tax applied
_get_customer_info
$customer_info = $this->_get_customer_info(NULL, $return_shipping = FALSE);
This returns an array of all of the customer information. It is critical that you set the second parameter to false otherwise this function will get stuck in and endless loop trying to access the selected shipping plugin.
_get_alpha2_country_code
$country_code = $this->_get_alpha2_country_code($orig_country_code);
Converts 3 (or 2) character country codes to 2 character country codes.
data_array_to_string
$data_string = $this->data_array_to_string($data_array);
Converts an array to a URL encoded string. Useful for sending through cURL.
curl_transaction
$result = $this->curl_transaction($url, $data_string);
Sends data to specified URL, return the response.
User selectable rates
If the customer can select from available rates, you’ll need a method of outputting these rate choices. The functions below describe the process of outputting these choices for your customer.
plugin_shipping_options
The plugin_shipping_options function is where you need to build any settings that the customer will see. This should return a string of HTML containing a form input field with the name set to “shipping_option”.
That’s it for now: I’ll add more detail to this at a later date. Please contact us in the meantime, if you plan on developing your own shipping plugin and need more information about how it is done. These docs are a work in progress, so please be patient while we work on them. We’d rather provide what information we can, and build upon it, so apologies that this subject is not completely covered at the current time

