[Drupal] How to use Drupal Ubercart Shipping module

| | 2 min read

Needing a Ubercart module that will calculate the shipping price for various regions depending upon the total weight of the products ordered. Ubercart shipping module is an interface to add different shipping providers. It's worth mentioning what we're trying to achieve here. Cotswold Seeds wanted to provide a single shipping cost for every order, as depending on shipping address, the order value and weight, they have the responsibility of selecting the shipping carrier.Only a single shipping quote is ever going to be provided for each order, because The user would not be given a choice here.

hook_shipping_method is the main hook that we need to implement in order to tell Ubercart. So the module provides shipping method and get onto the quote stuff later.

Everything is straightforward and this follows a familiar Drupal pattern of returning an array representing a shipping method. Here return multiple arrays here if you wanted to provide more than one method, but only want one.

Set up implementation of hook_shipping_method, we named a callback function to be responsible for generation the actual quote.

Note that the 'quote' attribute here contains a 'callback', which specifies which function to use in order to get the quote itself, and an 'accessorials', which is a bit confusing. Accessorials are end up on the customer's invoice, underneath the individual line items, to tell the customer what sort of delivery or shipping is taking place.

The quote function return an array from this function called $quotes. Array of arrays re $quotes and each of the inner arrays represents a quote.

You can either set the shipping quote as "Flat rate quote" or as "Weight quote" depending on your need. Each of them needs certain conditions for it to satisfy.

For example we can set the condition as

  • 1.Check an order's shipping country
  • 2.Check an order's number of products

We can set the conditions using "AND" and "OR".

If all the condition are satisfy we set the state as "AND" and if we need to choose among the conditions we use "OR" and then save the changes.

Now you can start to test the shipping quotes you have created by adding contents to the cart.

Reference: drupal.org