Blog/ Configuring Flat Shipping Rate Based On The Shopper's Shipping Address

By jojy.alphonso Tue, 03/22/2016 - 00:30 Comments

This is tutorial #16 in the Drupal Commerce tutorial series. Earlier, we added a basic shipping rate of $10 to every order placed on the site. In this article, we will go a step further and determine shipping rates based on the shopper's location.

I am going to charge a flat rate of $15 if the shipping address is for California. All other states will continue having the $10 shipping rate.

The following screenshots will highlight what we seek to achieve through this article.

A shipping flat rate of $15 for all California-based orders:

And a shipping flat rate of $10 for all other states:

To begin with, click “Store”:

Click “Configuration”:

Click “Shipping”:

You will notice the default flat rate already present there  –  it’s the one we configured to impose a $10 flat rate. Click “Add a flat rate service”:

In the new screen, I want you to create a new flat rate. Give it a custom title and display of your choice. I have given a base rate of $15 as can be seen below. Click “Save flat rate”:

The new flat rate has been saved:

Click configure component on the right of “Flat Rate For California”:

You will now be taken to the Rules page where you can configure how you want the new flat rate to behave. Notice the breadcrumb on the top to realize which page you have reached:

You will need to create two conditions. The first condition ensures that only American orders get the offer. The second condition ensures that only California is charged $15 shipping rates.

Click “Add condition”:

The page now expands to show multiple fields.

For the field “Select the condition to add”, select Order address component comparison. This ensures that the shipping address is validated :


Under “ADDRESS COMPONENT”, select Country. This is to specify that the flat rate is applicable only for orders from the USA:

Under “OPERATOR”, select equals:

Under “Value”, select US as the country you seek this tax rate for:

Let’s add one more condition so that only orders from California are imposed with the $15 shipping rate. Click “Add condition” once again:

Select Order address component comparison:

Select “Administrative area (State / Province)” from the dropdown. This signifies that you are laying down the condition for a state.

Under “OPERATOR”, select equals:

Under “VALUE”, I have typed in CA. The system accepts only 2 character for this field:

The conditions have now been saved:

Okay, now you have set the flat rate to impose a $15 on all orders originating from California. But there’s still more for you to do to make this possible. Remember the original $10 shipping flat rate for all states that was configured in the earlier article? You will have to set 2 conditions for it to ensure that the $10 shipping rate isn’t applied to California anymore.

Let’s go to “Store” -> “Configuration” -> “Shipping”. Click configure component: 

The first condition should reflect the country just like we did before. Select Order address component comparison:

Fill in the other fields like we did earlier:

Similarly, fill in details for California (CA):

Notice the “Negate” box has been ticked. This ensures that the $10 rate won’t be applied for orders that feature these fields – CA and USA. Here are the saved conditions for the $10 Rate Flat rate:

Let’s now add an OR group to club these conditions together. OR ensures that the conditions work together: 

OR gets added to the table. Let’s drag it to the very top:

Let’s now drag the conditions towards the right so that they become a part of the OR group:

Click “Save changes

Let’s now try checking out a product with a California shipping address. Let’s see how the bill reflects the shipping rate for deliveries in California and other states.

I am checking out my cart:

I provided a random California-based address:

Proceed to the next step. You will notice the $15 shipping rate being applied for my order:

Click forward to the final screen and you will see the $15 as part of the final bill. The functionality is working.

I’ll now perform a checkout to test whether a flat rate of $10 applies for non-California state orders:

I am using a New Mexico address:

Proceed further in the checkout process and you will notice a flat rate of $10 being added to the bill. This proves the functionality is correct:

In the final screen, you will see $10 added to the bill:

We have successfully added a flat shipping rate of $15 to California-based orders while keeping the rate $10 for all other states.

Next: Configuring FedEx For Your Drupal Store

Ready to get Started?