# How to setup a Drupal Commerce Order total Range condition

> A working Drupal Commerce Class to be used when willing to trigger Drupal Commerce condition once order total falls within a range of price.

Source: https://antistatique.net/en/blog/how-to-setup-a-drupal-commerce-order-total-range-condition

Category: Development

# How to setup a Drupal Commerce Order total Range condition

Author(s)

[

![Kevin](https://images.statique.ch/t/w_750,h_750,c_fill,f_jpeg,q_70/wp/app/uploads/2020/12/Kevin-300x300.jpg)



](/en/agence/kevin)

[Kevin](/en/agence/kevin)3 June 2022

The other day, I faced a **serious problem**. One of our clients wanted a new **shipping methods** that must be applied on **Ranged Order Total Price condition**.

AKA a shipping method that must apply only when the order total falls within a range. E.g. $100 => order total <= $200.

After digging the [Drupal Commerce Issue Queue](https://www.drupal.org/project/commerce/issues/2938731), I found out there is **no out-of-the-box solution/patch** (for now) to apply an Order Total Price within a range Condition. **So let's code it !**

This is what you will be able to achieve at the end of this story

> “ Truth can only be found in one place: the code ”
> 
> Robert C. Martin
> 
> Clean Code: A Handbook of Agile Software Craftsmanship

## The Plugin Condition

For the most curious ones, here is a **unit test** Class that you may be interested to add on your project to ensure plugin stability: [https://gist.github.com/WengerK/edbe17bb52067c5be86f34d1d1d2bd4e#file-ordertotalpricerangetest-php](https://gist.github.com/WengerK/edbe17bb52067c5be86f34d1d1d2bd4e#file-ordertotalpricerangetest-php).

> “ Well done you did it ! ”
> 
> Shia LaBeouf

That's **pretty much all the hocus-pocus that you need** to have custom Commerce Total Price Order Condition fitting within a range.

## Going Further

The code upper here is simplified.

Still, you may want to change the code in order to **exclude adjustments** or change the **in between operators used**.

**Total price includes adjustments**

You may want to **remove the adjustments (taxes, shipping, etc ...) in order to trigger the condition**.

Then update the `OrderTotalPriceRange::evalute` method.

```
// (...)

if (!$total_price) {
  return FALSE;
}

// Subtract tax & shipping adjustments.
$adjustments = $order->collectAdjustments(array_filter(['tax', 'shipping']));
foreach ($adjustments as $adjustment) {
  $total_price = $total_price->subtract($adjustment->getAmount());
}

// (...)
```

**Configurable between operators**

The given plugin use a **hardcoded “Between” condition including the input values** (`>= && <=`).

You can still change this condition by updating the `return` condition of `OrderTotalPriceRange::evalute`.

```
return $total_price->greaterThan($condition_price_from)
      && $total_price->lessThan($condition_price_to);
```

## Credits

Many thanks to [Quentin Fahrner](https://www.drupal.org/u/renrhaf) for sharing with me an inital Plugin solution.

## Sources

For the most curious of you, here are some sources of additional information that inspired the creation of this article.

**Quentin Fahrner** (11 May, 2022). Order total range condition.  
See on [https://www.drupal.org/project/commerce/issues/2938731](https://www.qed42.com/blog/autocomplete-drupal-8)

Retrieve all the code on Gist: [https://gist.github.com/WengerK/edbe17bb52067c5be86f34d1d1d2bd4e](https://gist.github.com/Sudei/822510d2a069331a4bbe84ef55570705)

## We are ready to assist you with your [Drupal](https://antistatique.net/en/services/drupal) project

## More articles

Author(s)

[

![Anthony](https://images.statique.ch/t/w_750,h_750,c_fill,f_jpeg,q_70/wp/app/uploads/2024/11/anthony-1-300x300.png)



](/en/agence/anthony-salamone)

[Anthony](/en/agence/anthony-salamone)28 September 2026

### [Smashing Conference Freiburg 2026](/en/blog/smashing-conference-freiburg-2026)

Back in Freiburg for Smashing Conference 2026: AI and design systems, deeply technical CSS and HTML, and more human talks about teams and mindset. Here's what we took away.

Back in Freiburg for Smashing Conference 2026: AI and design systems, deeply technical CSS and HTML, and more human talks about teams and mindset. Here's what we took away.

[

![Smashing Conference Freiburg 2026 poster](https://images.statique.ch/t/w_750,h_500,c_fill,f_jpeg,q_70/assets/blog/smashing-2026.png)



](/en/blog/smashing-conference-freiburg-2026)

Author(s)

[

![Akira](https://images.statique.ch/t/w_750,h_750,c_fill,f_jpeg,q_70/wp/app/uploads/2025/03/akira-small-300x300.jpg)



](/en/agence/akira-kamata)

[Akira](/en/agence/akira-kamata)22 July 2026

### [Making of : “La nuit des Losers”](/en/blog/making-of-la-nuit-des-losers)

lanuitdeslosers.ch, built fast: paper wireframes, a bold hand-drawn identity, then Claude Code to prototype and ship. A mouse-tracking hero animation, a bowling game made of sponsor logos, and a few bugs we’re keeping.

lanuitdeslosers.ch, built fast: paper wireframes, a bold hand-drawn identity, then Claude Code to prototype and ship. A mouse-tracking hero animation, a bowling game made of sponsor logos, and a few bugs we’re keeping.

[

![Making of : “La nuit des Losers”](https://images.statique.ch/t/w_750,h_500,c_fill,f_jpeg,q_70/wp/app/uploads/2026/05/La-nuit-des-Losers-Teaser-1-768x576.png)



](/en/blog/making-of-la-nuit-des-losers)

Author(s)

[

![Pierre](https://images.statique.ch/t/w_750,h_750,c_fill,f_jpeg,q_70/wp/app/uploads/2020/12/Pierre-300x300.jpg)



](/en/agence/pierre)

[Pierre](/en/agence/pierre)7 July 2026

### [Dark mode: necessity or trend](/en/blog/dark-mode-necessity-or-trend)

Nous faisons le tri entre idées reçues, réalités techniques et bonnes pratiques de design.

Nous faisons le tri entre idées reçues, réalités techniques et bonnes pratiques de design.

[

![Dark mode: necessity or trend](https://images.statique.ch/t/w_750,h_500,c_fill,f_jpeg,q_70/wp/app/uploads/2026/07/1-768x384.png)



](/en/blog/dark-mode-necessity-or-trend)
