Skip to main content

Ajax Search Pro

The Ajax Search will be integrated with WooCommerce, and MultiVendor apps.

To have the feature on the app, please follow these steps:

  1. You need to install and activate the Ajax Search Pro plugin for your website.
  2. Next, go to the "Compatibility & Other Settings" page of the Ajax Search Pro plugin. You can find this page by navigating to "Ajax Search Pro" in your WordPress dashboard, and then clicking on "Compatibility & Other Settings".
  3. In the "Compatibility & Other Settings" page, click on the "Other" tab.
  4. Make sure that the "Enable REST API" checkbox is checked.
  5. Click on the "Save options" button at the bottom of the page to save your changes.

Then follow the 2 steps below:

1. Update FluxStore App

Using FluxBuilder: go to Features, select Search Product, enable Enable Ajax Search Pro plugin, then fill in the Ajax Search URL:

https://your-domain/wp-json/ajax-search-pro/v0/woo_search?s=

2. Update functions.php

Please go to the hosting control panel, and edit the functions.php file in the Theme folder to enable the search function from the API.

function asp_custom_rest_handler( $data ) {
$id = -2;
$defaults = $args = array(
's' => ''
);
foreach ( $defaults as $k => $v ) {
$param = $data->get_param($k);
if ( $param !== null ) {
$args[$k] = $param;
}
}

// Fetch the search ID, which is probably the WooCommerce search
foreach ( wd_asp()->instances->get() as $instance ) {
if ( in_array('product', $instance['data']['customtypes'] ) ) {
$id = $instance['id'];
break;
}
}

// No search was found with products enabled, set it explicitly
if ( $id == -2 ) {
$args['post_type'] = array('product');
}

$asp_query = new ASP_Query($args, $id);
return $asp_query->posts;
}

// POST to: http://example.com/wp-json/ajax-search-pro/v1/woo_search
add_action( 'rest_api_init', function () {
register_rest_route('ajax-search-pro/v0', '/woo_search', array(
'methods' => 'POST',
'callback' => 'asp_custom_rest_handler',
));
});

Check the API Search function is available when returning as the JSON, for example: [https://your-hosting.com]/wp-json/ajax-search-pro/v0/woo_search?s=[text]

3. Common search issues:

💊 Result page loop issues

With the Ajax Search Pro plugin, the default search query returns 10 search results. To retrieve all search results, you need to edit the plugin to return all results.

Please log in to your website as an administrator and set the limit for the returned product results to the desired value, for example: 100

💊 Filter not working with ASP -  If you use Ajax search, it can't apply the filter when loading the product

💊 The search product results cannot load images

The issue arises from not specifying a search ID, leading to the default route being utilized, where images are not parsed by default. Please log in to your website as an administrator and create a search instance configured specifically for product searches.