Tagged: woocommerce
-
AuthorPosts
-
May 1, 2015 at 7:24 am #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!
May 2, 2015 at 5:11 pm #438392Hi 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!
JosueMay 2, 2015 at 6:57 pm #438405Wait. How is a question about how the Enfold Ajax search drop down not a theme question?
May 3, 2015 at 7:37 am #438461Because 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!
JosueMay 6, 2015 at 6:29 am #440128Thanks 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!
May 6, 2015 at 7:31 pm #440597Hey!
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,
YigitJuly 28, 2015 at 5:05 pm #479808Hi, 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.
JeanJuly 31, 2015 at 8:15 am #481128Hi 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,
JosueJuly 31, 2015 at 10:10 am #481208Hi 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.
JeanAugust 1, 2015 at 4:42 am #481621Hi 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!
JosueFebruary 25, 2020 at 9:03 pm #1187829February 27, 2020 at 6:47 pm #1188553Hi Cloudypro,
Please have a look at the following thread:
If you need further assistance please let us know.
Best regards,
Victoria -
AuthorPosts
- You must be logged in to reply to this topic.