> For the complete documentation index, see [llms.txt](https://docs.umbraco.com/llms.txt). Markdown versions of documentation pages are available by appending `.md` to page URLs; this page is available as [Markdown](https://docs.umbraco.com/umbraco-commerce/17.latest/how-to-guides/create-custom-order-advanced-filter.md).

# Create a Custom Order Advanced Filter

Learn how to add a custom advanced filter to the order list in Umbraco Commerce.

The order list in the **Commerce** section includes advanced filters, such as **Order Number**, **First Name**, and **Placed On or After**. You can add your own filters to search orders by other criteria.

This guide shows how to create a filter that lists orders by payment method. Combined with the built-in date filters, it can show, for example, how many orders a store completed with a given payment method each week.

## Create the filter

An advanced filter is a class that inherits from `OrderAdvancedFilterBase`, decorated with the `AdvancedFilter` attribute.

1. Create a new class, for example `OrderPaymentMethodAdvancedFilter.cs`.
2. Add the following code:

```csharp
using Umbraco.Commerce.Cms.Filters;
using Umbraco.Commerce.Common.Specifications;
using Umbraco.Commerce.Core.Models;
using Umbraco.Commerce.Core.Specifications.Order;
using Umbraco.Commerce.Extensions;

namespace MyProject.Filters;

[AdvancedFilter("paymentMethod",
    Group = "order",
    Label = "Payment method ID",
    Description = "Orders that use the given payment method",
    EditorUiAlias = "Umb.PropertyEditorUi.TextBox")]
public class OrderPaymentMethodAdvancedFilter : OrderAdvancedFilterBase
{
    public override bool CanApply(string value)
        => Guid.TryParse(value, out _);

    public override IQuerySpecification<OrderReadOnly> Apply(
        IQuerySpecification<OrderReadOnly> query,
        IOrderQuerySpecificationFactory where,
        string value)
        => query.And(where.HasPaymentMethod(Guid.Parse(value)));
}
```

The filter has three parts:

* The `AdvancedFilter` attribute sets the filter's alias and how it appears in the backoffice:
  * `Group` places the filter in the **Order** group. The built-in groups are `order`, `customer`, and `orderLine`.
  * `Label` and `Description` are shown next to the filter.
  * `EditorUiAlias` sets the property editor used to enter the value. This example uses a text box.
* `CanApply` checks whether the entered value is valid. The filter is only applied when it returns `true`.
* `Apply` adds the filter condition to the order query. `HasPaymentMethod` is one of the conditions available on `IOrderQuerySpecificationFactory`.

## Register the filter

Register the filter with a composer so Umbraco Commerce adds it to the order list.

1. Create a new class, for example `OrderFiltersComposer.cs`.
2. Add the following code:

```csharp
using Umbraco.Cms.Core.Composing;
using Umbraco.Cms.Core.DependencyInjection;
using Umbraco.Commerce.Extensions;

namespace MyProject.Filters;

public class OrderFiltersComposer : IComposer
{
    public void Compose(IUmbracoBuilder builder)
        => builder.WithUmbracoCommerceBuilder()
            .WithOrderAdvancedFilters()
            .Add<OrderPaymentMethodAdvancedFilter>();
}
```

3. Build and restart the site.

## Use the filter

The filter needs the ID of the payment method to filter on.

1. Go to the **Settings** section.
2. Expand your store under **Stores** and select **Payment Methods**.
3. Select the payment method.
4. Copy the **Id** from the **Info** panel.

![The payment method ID in the Info panel](https://3343668521-files.gitbook.io/~/files/v0/b/gitbook-x-prod.appspot.com/o/spaces%2FlHETtFOx4I72xhuc27Kt%2Fuploads%2Fgit-blob-38ed0498ab2215b050f59671fada41e916b754ba%2Fpayment-method-id.png?alt=media)

To filter the order list:

1. Go to the **Commerce** section.
2. Expand your store and select **Orders**.
3. Select the filter icon next to **Payment Status**.
4. Enter the ID in **Payment method ID**.

![The Payment method ID filter in the Advanced Filters panel](https://3343668521-files.gitbook.io/~/files/v0/b/gitbook-x-prod.appspot.com/o/spaces%2FlHETtFOx4I72xhuc27Kt%2Fuploads%2Fgit-blob-63b51524345265d7556f76fac7b456612f1adb92%2Fadvanced-filters-panel.png?alt=media)

5. Select **Apply**.

The order list shows only the orders that use the given payment method.

![The order list filtered by payment method](https://3343668521-files.gitbook.io/~/files/v0/b/gitbook-x-prod.appspot.com/o/spaces%2FlHETtFOx4I72xhuc27Kt%2Fuploads%2Fgit-blob-f804b533b8e5e3e1fe920e26db0af92714958773%2Ffiltered-order-list.png?alt=media)

To count the orders for a specific week, also set **Placed On or After** and **Placed On or Before** in the **Advanced Filters** panel.


---

# Agent Instructions
This documentation is published with GitBook. GitBook is the documentation platform designed so that both humans and AI agents can read, navigate, and reason over technical content effectively. Learn more at gitbook.com.

## Querying This Documentation
If you need additional information that is not directly available in this page, you can query the documentation by asking a question.

Perform an HTTP GET request on the following URL with the `ask` and `goal` query parameters:

```
GET https://docs.umbraco.com/umbraco-commerce/17.latest/how-to-guides/create-custom-order-advanced-filter.md?ask=<question>&goal=<user_goal>
```

`ask` is the immediate question: it should be specific, self-contained, and written in natural language.
`goal` is what the user is ultimately trying to achieve, the reason they need the answer. Sharing it helps GitBook give you a better, more relevant answer. A goal is most helpful when it describes the outcome the user wants rather than restating the question. For example, with `ask=how do I create an API token`, a goal like `automate deployments from our CI pipeline` lets GitBook tailor the answer to that use case.

The response will contain a direct answer to the question and relevant excerpts and sources from the documentation.

Use this mechanism when the answer is not explicitly present in the current page, you need clarification or additional context, or you want to retrieve related documentation sections.
