Drupal Commerce: Adding flat rate shipping option if there are certain SKUs or Product Types in the order

Wed, 10/15/2014 - 17:23 -- admin

Modules you will need

Follow these steps

  • Navigate to Store -> Configuration -> Shipping -> Flat rate -> Add a flat rate service
  • Fill out the fields on this page, click save, and you will have your flat rate service created
  • Now navigate to Configuration -> Workflow -> Rules -> Components
  • Find the Rule that pertains to the flat rate service you just added (it will be prefixed with "Rate", edit that Rule
  • On the following page, add a condition for Commerce Order: Order contains products
  • Your data selector should already be set to commerce_order
  • Enter in a comma separated list of product SKUs in the "Product SKU(s)" field -- these are SKUs that you would like to trigger the addition of this flat rate as a shipping option
  • Save the condition

Optional configuration

  • Click on the "Add and" link under Conditions, then hit continue on the following screen
  • OPTIONAL: Select the "Add condition" link one more time once the page refreshes, and this time we are going to choose "Order contains products of particular product types"
  • On the following page leave "commerce_order" as the Data selector.  You should see all of the product types on your site in the dropdown under "Product Type(s)".  Depending on what you want to do here, you would either choose the types you do want to trigger the flat rate to be an option, or the types you don't want to trigger the flat rate to be an option.
  • In this example, I only want the flat rate to show up if specific SKUs are in the order AND the flat rate needs to not show up if there are any products from categories other than the one that contains the SKUs.
  • To accomplish the very confusing sentence above, we will select the Product Type from the "Product Type(s)" field that we do not want to trigger the flat rate option
  • Change the operator to "=", and the Quantity to "0"
  • So now, the flat rate we have defined will only be applied to the order as a shipping option if:
    • The order contains products that match the SKU list we provided
    • AND
    • The order contains 0 products of the type we selected (in this case "T-Shirts", the product type that we do not want to trigger the flat rate)