skip to Main Content

I have my products ordered by most sold, with the built in function in Woocommerce. But I want to put a few products on the top even if they are not the most sold. Can this be done with some custom code?

For example, create a custom sort by most sold, but if these products ID(s) are present, put them on top?

2

Answers


  1. Chosen as BEST ANSWER

    I manage to solve this by using this code:

    add_filter( 'woocommerce_default_catalog_orderby', 'custom_default_catalog_orderby' );
    function custom_default_catalog_orderby() {
      if (is_product_category( array( 'cat-123' ))) {
        return 'date';
      }
    }
    

    For a specific category I change the orderby to date and then set date accordingly as the order that I want. The rest of the products in all the other categories are sorted by most sold.

    Not the way I asked the question, but its another way to achieve what I want.


  2. To arrange your product as your wish you can use plugins like:

    Rearrange Woocommerce Products

    . And also you can use WooCommerce settings too. You can change menu order as you wish.

    path:

    Edit of any individual product → scroll down to the Product data widget → click on the Advanced tab, where you will find the Menu order for changing the order.
    

    or you can

    Adjust Sold Count

    of your products..

    Login or Signup to reply.
Please signup or login to give your own answer.
Back To Top
Search