Skip to content

Instantly share code, notes, and snippets.

@webdados
Last active November 11, 2025 16:25
Show Gist options
  • Select an option

  • Save webdados/1f5c13bfc021fb82a1e20014b3fa48c9 to your computer and use it in GitHub Desktop.

Select an option

Save webdados/1f5c13bfc021fb82a1e20014b3fa48c9 to your computer and use it in GitHub Desktop.
Filter results on Shop as Client PRO autocomplete search
<?php
add_filter( 'shop_as_client_autocomplete_results', function ( $results, $search_term ) {
// Loop through results and modify/remove them
foreach( $results as $key => $result ) {
// Get the type of result and its ID, as $key is sequencial and not related to the result
$result_value = explode( ':', $result['value'] );
switch( $result_value[0] ) {
case 'user':
$user_id = intval( $result_value[1] );
// example: remove this user from results if its role is 'subscriber'
$user = get_user_by( 'ID', $user_id );
if ( in_array( 'subscriber', (array) $user->roles, true ) ) {
unset( $results[ $key ] );
}
break;
case 'order':
$order_id = intval( $result_value[1] );
// example: remove this order from results if its total is below 50
$order = wc_get_order( $order_id );
if ( $order && $order->get_total() < 50 ) {
unset( $results[ $key ] );
}
break;
}
}
return $results;
}, 10, 2 );
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment