WooCommerce Hooks

Customize shop filters, sorting, and order search for WooCommerce integration.

Browse & Catalog

celersearch_woocommerce_browse_filters

Filter the normalized filter conditions for WooCommerce browse/catalog queries (shop page, category archives, tag archives).

PHP
add_filter('celersearch_woocommerce_browse_filters', function($filters, $query) {
    // Only show featured products
    $filters[] = [
        'field'    => 'is_featured',
        'operator' => '=',
        'value'    => true,
    ];

    // Exclude out-of-stock by default
    $filters[] = [
        'field'    => 'in_stock',
        'operator' => '=',
        'value'    => true,
    ];

    return $filters;
}, 10, 2);
ParameterTypeDescription
$filtersarrayNormalized filter conditions
$queryWP_QueryThe WordPress query

Filters are built from URL parameters (min_price, max_price, rating_filter, filter_pa_*, _product_cat, _product_tag, etc.) before this hook runs.


celersearch_woocommerce_sort

Filter the sort rules for WooCommerce browse queries.

PHP
add_filter('celersearch_woocommerce_sort', function($sort, $orderby, $query) {
    // Add custom sort option
    if ($orderby === 'bestselling') {
        return ['total_sales:desc'];
    }

    // Modify default date sort to include title as tiebreaker
    if ($orderby === 'date') {
        return ['post_date:desc', 'title:asc'];
    }

    return $sort;
}, 10, 3);
ParameterTypeDescription
$sortarraySort rules (e.g., ['price:asc'])
$orderbystringThe WooCommerce orderby parameter value
$queryWP_QueryThe WordPress query

Default sort mapping:

Orderby ValueSort Rules
popularity['total_sales:desc']
rating['ratings.average_rating:desc']
date['post_date:desc']
price['price:asc']
price-desc['price:desc']

When no orderby is set, an empty array is returned (uses relevance).


celersearch_shop_filters_js_config

Filter the JavaScript configuration for the AJAX shop filter UI.

PHP
add_filter('celersearch_shop_filters_js_config', function($config) {
    // Customize translations
    $config['i18n']['noResults'] = __('Sorry, no products match your filters.', 'my-theme');

    // Add custom filter sections
    $config['filterSections']['taxonomies.pa_brand'] = __('Brand', 'my-theme');

    return $config;
});
ParameterTypeDescription
$configarrayThe JS configuration object

Config structure:

KeyTypeDescription
restUrlstringREST endpoint URL for shop filter
noncestringWordPress REST nonce
indexIdintThe Products index ID
stylestringFilter bar style
i18narrayTranslatable UI strings
currentFiltersarrayPre-selected context filters (category/tag archive)
filterSectionsarrayFacet key => label mapping for filter UI sections

celersearch_should_intercept_order_query

Control whether CelerSearch handles WooCommerce order searches in admin.

PHP
add_filter('celersearch_should_intercept_order_query', function($should_intercept) {
    // Disable for non-admin users
    if (!current_user_can('manage_woocommerce')) {
        return false;
    }

    return $should_intercept;
});
ParameterTypeDescription
$should_interceptboolWhether to intercept (default: true)

This runs after verifying CelerSearch is enabled and a WooCommerce orders search area is configured.


celersearch_select_orders_index

Programmatically select which index to use for order searches.

PHP
add_filter('celersearch_select_orders_index', function($index) {
    // Use a specific index for orders
    $repo = new \CelerSearch\Repositories\IndexRepository();
    return $repo->find_by_slug('woocommerce-orders');
});
ParameterTypeDescription
$indexIndexConfig|nullCurrently selected index (default: null)

Priority order:

  1. Search area configuration (orders area index_id)
  2. This filter
  3. Default index (if its type is orders)

celersearch_order_search_params

Modify search parameters before order search execution.

PHP
add_filter('celersearch_order_search_params', function($params, $search_term, $query_args, $index) {
    // Increase result limit
    $params['limit'] = 50;

    // Add date range filter
    $params['filters'][] = [
        'field'    => 'date_created',
        'operator' => '>=',
        'value'    => strtotime('-30 days'),
    ];

    return $params;
}, 10, 4);
ParameterTypeDescription
$paramsarraySearch parameters
$search_termstringThe search query
$query_argsarrayOriginal WooCommerce order query args
$indexBaseIndexThe orders index

Parameters structure:

PHP
[
    'q'       => 'search term',
    'limit'   => 20,
    'offset'  => 0,
    'filters' => [
        [
            'field'    => 'status',
            'operator' => '=',
            'value'    => 'completed',
        ],
    ],
]