Crash Course

Tree Table Rate

You might be wondering why there is 'Tree' word in the plugin name? That is explained below.

Configuration we've got in the previous step might be felt not so clean as it should be. We have repeated same destination condition (Destination is New Zealand) and titles (Domestic Shipping, International Shipping) multiple times. It's probably ok for such a simple case but in a more complex setup, keeping, say, 5 conditions in sync between two rules would be awkward and error-prone. Some day you will forget to mirror changes.

So what we can do with that?

We can use the magic of the Tree.

For now we have a flat rule list (so called table-rate). However, in some cases it's more convenient to organize one or more rules under a common parent rule, converting that flat list into the tree of rules. That trick might be used for a number of purposes. One of it is extracting common conditions and calculations from two or more rules to a parent. That's what we'll do next.

  • Add another rule in the same way you did that before;
  • Type Domestic Shipping in both Title and Label fields;
  • Add Destination is New Zealand condition similar to what we have in domestic shipping rules;
  • Move the rule to the top.
Parent rule introduced

Now collapse rule settings. Although it's not necessary it just would be more comfortable to do so at the first time. Now grab the Free for $130+ rule and move it right under the newly created one. Do not drop it for now. You will notice a dashed placeholder frame marking the place where rule you are currently dragging is going to be dropped at. Now pull the rule a bit right until the placeholder jumps right too. At the moment you will also notice that the newly created rule header became darker and more massive reflecting the fact that it has child rules. Now you can drop the rule. Dropping a child rule

Repeat same for the second domestic rule. Domestic rules refactored

At this moment you can remove duplicated data. Clear titles and remove destination conditions from both child rules. Duplicate data cleaned

Do the same for the international shipping rules for the sake of consistency. You will have the tree like on the screenshot. Save settings. International rules refactored

Test the result on the cart page. It should be same as on previous step if everything's done right. Result did not change after refactoring

On the next step we will learn how to offer multiple delivery options to the customer.