Skip to main content
Merchant Buddy provides a number of filters to allow you to customize entities and providers without needing to create your provider or entity.

merchant_buddy_available_providers

Filters the list of available search providers, it’s also the way to add your own search provider. Available providers are surfaced in the search settings page.

Parameters

providers
array
List of providers with their class name.

Default providers

$default_providers = [
    "algolia" => Nadir\MerchantBuddy\Providers\Algolia::class,
    "default" => Nadir\MerchantBuddy\Providers\DefaultProvider::class
];

Example

Add a provider to the list of available providers.
add_filter( 'merchant_buddy_available_providers', function( $providers ) {
  $providers['my_provider'] = Providers\MyProvider::class;
  return $providers;
});
Or remove a provider from the list of available providers.
add_filter( 'merchant_buddy_available_providers', function( $providers ) {
    unset( $providers['algolia'] );
    return $providers;
});

merchant_buddy_available_entities

Filters the list of available searchable entities, it’s also the way to add your own searchable entity. Available entities are surfaced in the search settings page.

Parameters

entities
array
List of entities with their class name.

Default entities

$default_entities = [
    "orders" => Nadir\MerchantBuddy\Entities\Orders::class,
    "products" => Nadir\MerchantBuddy\Entities\Products::class,
    "customers" => Nadir\MerchantBuddy\Entities\Customers::class
];

Example

Add a new searchable entity.
add_filter( 'merchant_buddy_available_entities', function( $entities ) {
    $entities['invoices'] = Entities\MyInvoices::class;
    return $entities;
});
Remove an entity from the list of available entities.
add_filter( 'merchant_buddy_available_entities', function( $entities ) {
    unset( $entities['customers'] );
    return $entities;
});

merchant_buddy_{entity}_display_fields

Filters the list of attributes that should be returned in a entity search result. Those are the props used to render the entity in the search results.

Parameters

display_fields
string[]
default:"[]"
List of display fields. Return an empty array to return all properties.

Example

add_filter( 'merchant_buddy_orders_display_fields', function( $display_fields ) {
    if ( ! in_array( 'order_number', $display_fields ) ) {
        $display_fields[] = 'order_number';
    }
    return $display_fields;
});

merchant_buddy_{entity}_searchable_fields

Filters the list of attributes that should be used to search for an entity. Proviers that support indexing can use those attributes to index an entity using them. By default, all fields are used.

Parameters

searchable_fields
string[]
default:"[]"
List of searchable fields. Return an empty array to use all fields.

Example

add_filter( 'merchant_buddy_customers_searchable_fields', function( $searchable_fields ) {
    if ( ! in_array( 'billing_phone', $searchable_fields ) ) {
        $searchable_fields[] = 'billing_phone';
    }
    return $searchable_fields;
});

merchant_buddy_{entity}_item_data

Filter the item data that will be passed to providers.

Parameters

item_data
array
Item data, depends on the entity.
item
object
The item object, depends on the entity.

Example

add_filter( 'merchant_buddy_orders_item_data', function( $item_data, $item ) {
    $item_data['order_number'] = $item->get_order_number();
    return $item_data;
}, 10, 2 );