Tagged: 

Viewing 12 posts - 1 through 12 (of 12 total)
  • Author
    Posts
  • #437927

    Hi there. I’m using Enfold on a site that is primarily for ecommerce (using WooCommerce) but also has a blog. I’d like to have products display as the first section in the search results before posts and pages in the ajax search results. Is there a way to make that happen?

    Also, I noticed that for products on the search results page, it displays whether or not the product is a “simple” or “variable” product (from the WooCommerce taxonomy “product_type” along with the actual product category. And users can click through those links to view products. Is there a way to remove the “product_type” terms from the search results metadata?

    Thanks!

    #438392

    Hi Kevin!

    Not exactly a theme-related request but more of a WordPress one. However, this plugin could have that feature:
    https://wordpress.org/plugins/relevanssi/

    Cheers!
    Josue

    #438405

    Wait. How is a question about how the Enfold Ajax search drop down not a theme question?

    #438461

    Because the Enfold ajax search uses the get_posts WordPress function which orders posts by post_date and doesn’t support a custom ordering based on post type order.

    However as we already group the returning $posts by post type it would be just a matter of doing a re-order, try adding this after line in 185 in functions-enfold.php:

    /* Look for Products and place them at the start of the array */
    if (array_key_exists('product', $sorted)) {
        $products_array['product'] = $sorted['product'];
        unset($sorted['product']);
        $sorted = array_merge($products_array, $sorted);
    }

    So that basically 1) checks if there are products on the search results, 2) stores them on a separate array, 3) removes them from the main array and finally 4) both get merged but with the products one at the start.

    Also place this around line 173 to avoid PHP undefined notices:

    $products_array = array();
    

    Cheers!
    Josue

    #440128

    Thanks for this solution. This accomplished exactly what I was hoping for. I’m curious, though: since this modifies a file from the Enfold theme, what happens if you update functions-enfold.php in a future version of Enfold? Does this change get blown away on my site?

    Thanks!

    #440597

    Hey!

    Yes, changes you made will be lost. You can use a child theme – http://kriesi.at/documentation/enfold/using-a-child-theme/ and move the function to functions.php file of your child theme to avoid it

    Best regards,
    Yigit

    #479808

    Hi, it does not work in a child theme warning :
    Warning: array_key_exists() expects parameter 2 to be array, null given in /home/wp*cuISa/www/wp-content/themes/sagne-cuisines/functions.php on line 4
    Same in the Enfold functions.php…

    Regards.
    Jean

    #481128

    Hi Jean!

    Have you copied the whole avia_ajax_search function (134-255) to your child functions.php?

    if(!function_exists('avia_ajax_search'))
    {
    ....
    }

    Best regards,
    Josue

    #481208

    Hi Josue, no I had not copied to the child function.php the theme, now it is no more error message.
    In fact I wish that products arrive first research on the ajax search and if possible do not show here the results articles (just here).

    Regards.
    Jean

    #481621

    Hi Jean,

    Try changing the code i provided here, to:

    if (array_key_exists('product', $sorted)) {
        $products_array['product'] = $sorted['product'];
        unset($sorted['product']);
        $sorted = $products_array;
    }

    Cheers!
    Josue

    #1187829

    Hello @Yigit , @Josue

    How can i display the price of the product in the ajax search ?

    #1188553

    Hi Cloudypro,

    Please have a look at the following thread:

    Change Search results to products search results (Woocommerce)

    If you need further assistance please let us know.

    Best regards,
    Victoria

Viewing 12 posts - 1 through 12 (of 12 total)
  • You must be logged in to reply to this topic.