Home Forums WoodMart support forum Products (grid or carousel) Reply To: Products (grid or carousel)

#135269

Artem Temos
Keymaster

Try to add the following PHP code snippet to the child theme functions.php file

function woodmart_action_autocomplete(){
    remove_filter( 'vc_autocomplete_woodmart_products_include_callback',    'vc_include_field_search', 10, 1 ); // Get suggestion(find). Must return an array
    add_filter( 'vc_autocomplete_woodmart_products_include_callback',   'vc_include_field_search_product', 10, 1 ); // Get suggestion(find). Must return an array
}
add_action( 'init', 'woodmart_action_autocomplete', 500 );
function vc_include_field_search_product( $search_string ) {
    $query = $search_string;
    $data = array();
    $args = array(
        's' => $query,
        'post_type' => 'product',
    );
    $args['vc_search_by_title_only'] = true;
    $args['numberposts'] = -1;
    if ( 0 === strlen( $args['s'] ) ) {
        unset( $args['s'] );
    }
    add_filter( 'posts_search', 'vc_search_by_title_only', 500, 2 );
    $posts = get_posts( $args );
    if ( is_array( $posts ) && ! empty( $posts ) ) {
        foreach ( $posts as $post ) {
            $data[] = array(
                'value' => $post->ID,
                'label' => $post->post_title,
                'group' => $post->post_type,
            );
        }
    }
    return $data;
}