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).
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);
| Parameter | Type | Description |
|---|---|---|
$filters | array | Normalized filter conditions |
$query | WP_Query | The 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.
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);
| Parameter | Type | Description |
|---|---|---|
$sort | array | Sort rules (e.g., ['price:asc']) |
$orderby | string | The WooCommerce orderby parameter value |
$query | WP_Query | The WordPress query |
Default sort mapping:
| Orderby Value | Sort 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.
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;
});
| Parameter | Type | Description |
|---|---|---|
$config | array | The JS configuration object |
Config structure:
| Key | Type | Description |
|---|---|---|
restUrl | string | REST endpoint URL for shop filter |
nonce | string | WordPress REST nonce |
indexId | int | The Products index ID |
style | string | Filter bar style |
i18n | array | Translatable UI strings |
currentFilters | array | Pre-selected context filters (category/tag archive) |
filterSections | array | Facet key => label mapping for filter UI sections |
Order Search
celersearch_should_intercept_order_query
Control whether CelerSearch handles WooCommerce order searches in admin.
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;
});
| Parameter | Type | Description |
|---|---|---|
$should_intercept | bool | Whether 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.
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');
});
| Parameter | Type | Description |
|---|---|---|
$index | IndexConfig|null | Currently selected index (default: null) |
Priority order:
- Search area configuration (orders area
index_id) - This filter
- Default index (if its type is
orders)
celersearch_order_search_params
Modify search parameters before order search execution.
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);
| Parameter | Type | Description |
|---|---|---|
$params | array | Search parameters |
$search_term | string | The search query |
$query_args | array | Original WooCommerce order query args |
$index | BaseIndex | The orders index |
Parameters structure:
[
'q' => 'search term',
'limit' => 20,
'offset' => 0,
'filters' => [
[
'field' => 'status',
'operator' => '=',
'value' => 'completed',
],
],
]