Issue with Applying Changes to Product Search on header Ajax search bar

This topic has 2 replies, 2 voices, and was last updated 11 months, 3 weeks ago ago by Rose Tyler

  • Avatar: Matias Urquiza
    MioBio Chile
    Participant
    October 26, 2023 at 20:31

    Dear Support Team,

    I hope this message finds you well. I am currently experiencing difficulties trying to apply changes to the product search on the frontend of my store using your theme.

    My goal is to filter and sort search results based on specific categories. I have attempted to implement the following code in my functions.php file:

    function mi_filtro_de_busqueda($query) {
    // Verificamos si estamos en el frontend y en la búsqueda de productos
    if (!is_admin() && $query->is_search() && $query->get(‘post_type’) === ‘product’) {
    // Obtenemos las categorías que queremos priorizar
    $categories = array(‘para-leches-vegetales’, ‘licuadoras’, ‘extractores-de-jugo’, ‘para-harinas-y-pan’, ‘filtros-de-agua’, ‘para-el-jardin’, ‘repuestos’, ‘utensilios-de-hogar-y-cocina’, ‘deshidratador’);

    // Filtramos los resultados de la búsqueda
    $query->set(‘tax_query’, array(
    ‘relation’ => ‘AND’,
    array(
    ‘taxonomy’ => ‘product_cat’,
    ‘field’ => ‘slug’,
    ‘terms’ => $categories,
    ),
    ));

    // Ordenamos los productos por categorías y precio
    $query->set(‘orderby’, array(‘taxonomy’ => ‘ASC’, ‘meta_value_num’ => ‘DESC’));
    }
    }

    // Añadimos el filtro a la acción ‘pre_get_posts’
    add_action(‘pre_get_posts’, ‘mi_filtro_de_busqueda’);

    However, it seems that the changes are not being applied correctly. Could you please review the code and provide guidance on the best way to customize product search on the frontend using your theme?

    I appreciate your assistance and prompt response.

    Please, contact administrator
    for this information.
    1 Answer
    Avatar: Rose Tyler
    Rose Tyler
    Support staff
    October 27, 2023 at 09:53

    Hello, Matias Urquiza,

    Thank you for contacting us and for using XStore.

    Your question is about additional customization in files, please note that additional customization is not included in our basic support – https://prnt.sc/7ZySApKy_p2n

    If you would like to pursue paid customization services, we recommend submitting a customization request to the Codeable team via their website: https://www.codeable.io/?ref=qGTdX

    Kind Regards,
    8theme team

  • Viewing 2 results - 1 through 2 (of 2 total)

You must be logged in to reply to this topic.Log in/Sign up

8theme customization service
We're using our own and third-party cookies to improve your experience and our website. Keep on browsing to accept our cookie policy.