Skip to main content

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​

HookTypeArgumentsUse
wc_search_orders_by_product_readyactionWC_Search_Orders_By_Product $pluginFires on plugins_loaded (priority 20). Start add-ons here.
wc_search_orders_by_product_loadedactionnoneKept 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​

HookTypeArgumentsUse
wc_search_orders_by_product_filter_fieldsfilterarray $fieldsAdd, remove or reorder filters
wc_search_orders_by_product_requestfilterarray $valuesThe cleaned filter values read from the URL
wc_search_orders_by_product_is_filteringfilterbool $filtering, array $valuesWhether the list is being filtered
wc_search_orders_by_product_conditionsfilterstring[] $conditions, array $values, string $storage, string $id_columnSQL conditions added to the list query and its count. $storage is hpos or posts.
wc_search_orders_by_product_query_argsfilterarray $query_args, array $valueswc_get_orders() arguments of the filtered list (High-Performance Order Storage)
wc_search_orders_by_product_filteredactionarray $values, string $storageAfter the conditions are built
wc_search_orders_by_product_before_filtersactionstring $storagePrint markup before the controls
wc_search_orders_by_product_after_filtersactionstring $storagePrint markup after the controls
wc_search_orders_by_product_product_select_attributesfilterarray $attributesHTML attributes of the product search box
wc_search_orders_by_product_category_terms_argsfilterarray $argswp_dropdown_categories() arguments of the category filter
wc_search_orders_by_product_product_typesfilterarray $typesProduct types offered (slug => label)
wc_search_orders_by_product_lookup_availablefilterbool $available, string $storageForce matching through WooCommerce's order product lookup table (true) or order item meta (false)
wc_search_orders_by_product_recent_limitfilterint $limitMost recently changed orders matched through a list of IDs (default 2,000). Since 4.0.1.

Each entry of filter_fields has these keys:

KeyMeaning
query_varURL parameter
value_keyKey in the values array
labelText shown for the filter
descriptionOne line shown on the settings page
settingSettings key; empty means the filter is always on
defaultOn or off before the settings are first saved
sanitizeCallable that cleans the value
renderCallable 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​

HookTypeArgumentsUse
wc_search_orders_by_product_settings_sectionsactionarray $settingsSince 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_navfilterarray $navSince 4.1.0. Links in the Settings tab's section list, each [ section id, icon name, label ]
wc_search_orders_by_product_settings_after_fieldsactionarray $settingsMarkup at the end of the Orders list section
wc_search_orders_by_product_sanitize_settingsfilterarray $settings, array $rawSettings about to be saved. Add your own keys here; otherwise they are dropped.
wc_search_orders_by_product_capabilityfilterstring $capabilityCapability 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' );