Developer hooks
Add these to your theme's functions.php or a small plugin. They are available from version 4.0 and all start with wc_search_orders_by_product_.
Loading
| Hook | Type | Arguments | Use |
|---|---|---|---|
wc_search_orders_by_product_ready | action | WC_Search_Orders_By_Product $plugin | Fires on plugins_loaded (priority 20). Start add-ons here. |
wc_search_orders_by_product_loaded | action | none | Kept for compatibility. Fires before most plugins load, so add-ons usually miss it. |
wc_search_orders_by_product() returns the main object: ->engine (the query engine), ->filters (the filter list) and ->admin (the orders screen, in admin requests only).
The orders screen
| Hook | Type | Arguments | Use |
|---|---|---|---|
wc_search_orders_by_product_filter_fields | filter | array $fields | Add, remove or reorder filters |
wc_search_orders_by_product_request | filter | array $values | The cleaned filter values read from the URL |
wc_search_orders_by_product_is_filtering | filter | bool $filtering, array $values | Whether the list is being filtered |
wc_search_orders_by_product_conditions | filter | string[] $conditions, array $values, string $storage, string $id_column | SQL conditions added to the list query and its count. $storage is hpos or posts. |
wc_search_orders_by_product_query_args | filter | array $query_args, array $values | wc_get_orders() arguments of the filtered list (High-Performance Order Storage) |
wc_search_orders_by_product_filtered | action | array $values, string $storage | After the conditions are built |
wc_search_orders_by_product_before_filters | action | string $storage | Print markup before the controls |
wc_search_orders_by_product_after_filters | action | string $storage | Print markup after the controls |
wc_search_orders_by_product_product_select_attributes | filter | array $attributes | HTML attributes of the product search box |
wc_search_orders_by_product_category_terms_args | filter | array $args | wp_dropdown_categories() arguments of the category filter |
wc_search_orders_by_product_product_types | filter | array $types | Product types offered (slug => label) |
wc_search_orders_by_product_lookup_available | filter | bool $available, string $storage | Force matching through WooCommerce's order product lookup table (true) or order item meta (false) |
wc_search_orders_by_product_recent_limit | filter | int $limit | Most recently changed orders matched through a list of IDs (default 2,000). Since 4.0.1. |
Each entry of filter_fields has these keys:
| Key | Meaning |
|---|---|
query_var | URL parameter |
value_key | Key in the values array |
label | Text shown for the filter |
description | One line shown on the settings page |
setting | Settings key; empty means the filter is always on |
default | On or off before the settings are first saved |
sanitize | Callable that cleans the value |
render | Callable that prints the control |
Write a condition in the form "{$id_column} IN ( SELECT order_id FROM ... )". Avoid nesting one IN ( SELECT ... ) inside another: MySQL 5.7 runs the inner one once for every row.
Settings
| Hook | Type | Arguments | Use |
|---|---|---|---|
wc_search_orders_by_product_settings_sections | action | array $settings | Since 4.1.0. Print your own sections on the Settings tab, inside its form. Build them with the bundled kit, WC_Search_Orders_By_Product\AdminUI\Fields, so they match the page. |
wc_search_orders_by_product_settings_nav | filter | array $nav | Since 4.1.0. Links in the Settings tab's section list, each [ section id, icon name, label ] |
wc_search_orders_by_product_settings_after_fields | action | array $settings | Markup at the end of the Orders list section |
wc_search_orders_by_product_sanitize_settings | filter | array $settings, array $raw | Settings about to be saved. Add your own keys here; otherwise they are dropped. |
wc_search_orders_by_product_capability | filter | string $capability | Capability for the filters (edit_shop_orders) and the settings page (manage_woocommerce) |
wc_search_orders_by_product_settings_fields no longer runs since 4.1.0.
Settings are stored in the sobp_settings option, with switches as yes or no. Read one with wc_search_orders_by_product_setting_enabled( $key, $default ).
Examples
Offer only simple and variable products in the product type filter:
add_filter( 'wc_search_orders_by_product_product_types', function ( $types ) {
return array_intersect_key( $types, array_flip( array( 'simple', 'variable' ) ) );
} );
Always read order items directly, without the Analytics lookup table:
add_filter( 'wc_search_orders_by_product_lookup_available', '__return_false' );