Home › Forums › WoodMart support forum › Product sorting via search
Product sorting via search
- This topic has 5 replies, 2 voices, and was last updated 3 years, 9 months ago by Elise Noromit.
-
AuthorPosts
-
March 7, 2021 at 2:22 pm #271624
defjam2oo1Participantmy categories are sorted by popularity and works too.
But when I search on the search a product, they get results according to relevance. I can manually toggle it to popularity but I want it to be that way automatically.
I have to edit the product-searchform.php but unfortunately it doesn’t work. can you help me?Product-searchform.php
woodmart_search_form( array(
‘ajax’ => true,
‘post_type’ => ‘product’,
‘orderby’ => ‘popularity’
) );Example: I go to the Softdrinks Category. The first Product is Coca Cola 12×1,0L. This is also the most popular item.
Now I am searching for the article Cola and first see other articles because they are sorted by relevance.Attachments:
You must be logged in to view attached files.March 8, 2021 at 9:09 am #271755
Elise NoromitMemberHello,
Please add this code to the functions.php of the child.
add_filter( 'woocommerce_get_catalog_ordering_args', function( $args ) { if ( isset( $args['orderby'] ) && 'relevance' === $args['orderby'] ) { $args['orderby'] = 'popularity'; $args['order'] = 'DESC'; } return $args; } );
Best Regards
March 8, 2021 at 9:30 am #271768
defjam2oo1Participantunfortunately the snippet did not work. the search results are still sorted by Relevanz. you are welcome to look it up yourself.. I also deleted cache afterwards
ThanksMarch 9, 2021 at 10:13 am #272073
Elise NoromitMemberHello,
Please remove the code provided above and add this one to the functions.php of the child theme:
function wd_append_product_sorting_table_join( $sql ) { global $wpdb; if ( ! strstr( $sql, 'wc_product_meta_lookup' ) ) { $sql .= " LEFT JOIN {$wpdb->wc_product_meta_lookup} wc_product_meta_lookup ON $wpdb->posts.ID = wc_product_meta_lookup.product_id "; } return $sql; } function wd_order_by_popularity_post_clauses( $args ) { $args['join'] = wd_append_product_sorting_table_join( $args['join'] ); $args['orderby'] = ' wc_product_meta_lookup.total_sales DESC, wc_product_meta_lookup.product_id DESC '; return $args; } add_filter( 'woocommerce_get_catalog_ordering_args', function( $args ) { if ( isset( $args['orderby'] ) && 'relevance' === $args['orderby'] ) { add_filter( 'posts_clauses', 'wd_order_by_popularity_post_clauses' ); $args['orderby'] = 'popularity'; $args['order'] = 'ASC'; } return $args; } );
Best Regards
March 9, 2021 at 11:16 am #272099
defjam2oo1ParticipantIt works. I love this support. many thanks
March 9, 2021 at 11:43 am #272108
Elise NoromitMemberWe are always happy to help you, write to us when you have any difficulties or issues with our theme.
We would be grateful for 5 stars rate on http://themeforest.net/downloads in case you are satisfied with our theme and customer service
Thank you in advance
-
AuthorPosts
- You must be logged in to create new topics. Login / Register