Home › Forums › WoodMart support forum › Sorting Products: Display Sale Items at the Top & Sort by Price
Sorting Products: Display Sale Items at the Top & Sort by Price
- This topic has 5 replies, 2 voices, and was last updated 2 weeks, 3 days ago by
Aizaz Imtiaz Awan.
-
AuthorPosts
-
April 3, 2025 at 5:42 pm #651551
ark-way.comParticipantHello,
I would like to configure my shop so that products on sale appear at the top of the shop page and product categories by default, while simultaneously being sorted by price (from lowest to highest). I couldn’t find a built-in setting for this in Woodmart → Theme Settings → Shop → Sorting & Pagination.
Could you please advise on how to achieve this within Woodmart? Is there a built-in setting, or would I need custom modifications?
Thank you in advance!
Best regards,
Stefi, Ark Way AgencyApril 4, 2025 at 8:45 am #651645
Aizaz Imtiaz AwanKeymasterHello,
Navigate to Appearance > Customize > WooCommerce > Product Catalog > set the default product sorting.
https://ibb.co/CK9TQddBest Regards,
April 4, 2025 at 10:41 am #651703
ark-way.comParticipantHello,
Thank you for your response.
I’ve already tried setting the default product sorting via Appearance > Customize > WooCommerce > Product Catalog, but unfortunately, none of the available options allow me to:
Show sale (discounted) products first, and
Sort the rest by ascending price.
The sorting options provided only allow one type of sorting (e.g., by price or popularity), but not a combination. My goal is to have discounted products shown at the top, and then the rest of the products sorted by price (low to high).
Is there a way to achieve this with Woodmart, or would it require a custom solution?
Thank you in advance!
April 4, 2025 at 2:20 pm #651771
Aizaz Imtiaz AwanKeymasterHello,
There is no option available for this in the theme settings. This requires customization, which is beyond our support policy.
I have searched for a possible solution and found a custom function that you can add to your functions.php file. I have tested this code on our test site, and it is working fine.
If the provided code does not work as expected, unfortunately, we are unable to modify it further.
Add this to your theme’s functions.php file of the theme.
add_action( 'woocommerce_product_query', 'custom_sort_sale_first_then_price', 10, 2 ); function custom_sort_sale_first_then_price( $q, $query ) { if ( is_admin() || ! $q->is_main_query() || ! is_shop() && ! is_product_category() ) { return; } // Get meta queries $meta_query = $q->get( 'meta_query' ); // Set custom sorting $q->set( 'meta_query', $meta_query ); $q->set( 'orderby', array( 'sale_items' => 'DESC', 'price' => 'ASC' )); $q->set( 'meta_key', '_price' ); // Join sale price data add_filter( 'posts_clauses', 'custom_sale_products_first_clauses', 20, 2 ); } function custom_sale_products_first_clauses( $clauses, $query ) { global $wpdb; if ( is_shop() || is_product_category() ) { $clauses['join'] .= " LEFT JOIN {$wpdb->postmeta} AS sale_price_meta ON {$wpdb->posts}.ID = sale_price_meta.post_id AND sale_price_meta.meta_key = '_sale_price' "; $clauses['orderby'] = " (sale_price_meta.meta_value + 0) > 0 DESC, {$wpdb->postmeta}.meta_value + 0 ASC "; } return $clauses; }
This code will modify the main WooCommerce shop query to:
Show sale products first,
Then, sort everything by ascending price.Hope this Helps!
Best Regards,
April 11, 2025 at 3:28 pm #653422
ark-way.comParticipantHello,
Thank you for your support!
I’ve added the code manually via FTP, and it works exactly as expected — the sale products are listed first and the rest are sorted by ascending price.
Really appreciate your help!
Best regards,
Ark Way Agency teamApril 12, 2025 at 8:18 am #653539
Aizaz Imtiaz AwanKeymasterHello,
You’re very welcome! I’m glad I could help. If you need anything else, feel free to reach out!
Thanks for contacting us.
Have a great day.Topic Closed.
Best Regards, -
AuthorPosts
Tagged: sorting
The topic ‘Sorting Products: Display Sale Items at the Top & Sort by Price’ is closed to new replies.
- You must be logged in to create new topics. Login / Register