0

In Drupal Commerce, I'm trying to come up with a rule the bypasses shipping if virtual product types are put into the cart, but ONLY if all products are virtual; if physical products are put in, then the rule wouldn't fire because these products need to be shipped.

Below, for reference, is a solution for virtual products; it's close but it won't suffice if combined with both physical and virtual products.

Install Commerce Rules Extra

  • Create a rule for Event: Process checkout pane
  • Add Action: Change pane properties
  • Value: Shipping information
  • Page to move to: <do not change>
  • Enabled: uncheck
  • Add Condition: e.g. by Order contains products of particular product types, or based on Commerce order contains shippable products supplied by Commerce Physical Product. You may have to clear caches before this takes effect.
1

Commerce Shipping has a couple of ways you can approach this. The simplest is to set the weight of your virtual products to zero, they won't be assessed shipping charges, and they won't affect any weight based calculations.

EDIT: Alternatively, you can use Commerce Rules Extra to add conditions that exclude your virtual products in the conditions for your Flat Rate.

0

To bypass the shipping pane if the cart only contains virtual products, add an "and" condition that checks to see if the cart contains product types that are virtual or not shippable and if the cart does not contain product types that are shippable.

0

Here's a sketch of the way I've dealt with similar situations in a rule.

  • Create a variable to record outcome, eg. needs_shipping, defaulted to false
  • Loop through the items in the cart
  • If the current item is physical, set needs_shipping to true.

It's also possible to encapsulate this loop in code and call it from a rule, which will make the rules easier to maintain.

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.