• Resolved Denis

    (@butifarra)


    Hello. I want to order products by multiple fields (attributes, or arguments, as you prefer to call them).
    I want to order a machinery catalog by brand and between each brand by year, and between year by price. That is, for example:
    John Deere machines go first. Among all the John Deere, the order must be by year descending, and when the year coincides, the more expensive go first. How can I achieve this? I read a lot of material but nothing helpful. Thanks.

Viewing 6 replies - 1 through 6 (of 6 total)
  • Hi there,

    For this purpose, you can check out this article at WebHat: https://www.webhat.in/article/woocommerce-tutorial/custom-order-by-attributes/

    Please try the above and let us know how it goes.

    Thread Starter Denis

    (@butifarra)

    Hi again, I did what the page says, but it allows you to sort by one field OR another. I want to sort by one field AND another field inside that same group. It can be done easily in SQL adding two arguments when sorting, but I don´t know how to do it here.
    Machines have several brands, and every machine has a year and a value.
    Let’s see this simple case. I have 7 machines. 3 John Deere, 2 Case and 2 New Holland.
    Every machine has a different year model and value.
    John Deere 1590 year 2009 $ 15000
    John Deere 1580 year 2015 $ 10000
    John Deere 1780 year 2015 $ 20000
    Case 3030 year 2010 $ 20000
    Case 5050 year 2010 $ 10000
    New Holland 1515 year 2018 $ 50000
    New Holland 1520 year 2020 $ 40000
    I want the John Deere machines to appear first, after, the Case, and after, the New Holland. And, inside each subset, the order is year, and when the year coincides, by price.
    That is the order I want.
    John Deere 1780 year 2015 $ 20000
    John Deere 1580 year 2015 $ 10000
    John Deere 1590 year 2009 $ 15000
    Case 3030 year 2010 $ 20000
    Case 5050 year 2010 $ 10000
    New Holland 1520 year 2020 $ 40000
    New Holland 1515 year 2018 $ 50000

    Thread Starter Denis

    (@butifarra)

    Hi, do you have any suggestion? I can´t solve this. Thanks in advance.

    Hi there,

    You can check out https://stackoverflow.com/questions/44690734/multiple-order-by-in-woocommerce on how to include multiple order-by attributes.

    I hope this points you in the right direction.

    Thread Starter Denis

    (@butifarra)

    Hi again. I had found this post, but I don´t know if it is what I need, and if it is, I don´t realize how to make it work or if all the code I need for the functions.php file is there.

    Hi there,

    If you’re looking for custom code help, you might be able to find someone willing to volunteer their time and knowledge in the free PHP support forum at [PHP Builder](http://board.phpbuilder.com/forumdisplay.php?2-General-Help) or within the [Advanced WooCommerce](https://www.facebook.com/groups/advanced.woocommerce/) group on Facebook.

    I’m going to mark this as resolved – if you have any further questions, you can start a new thread.

Viewing 6 replies - 1 through 6 (of 6 total)

The topic ‘Order products by multiple fields’ is closed to new replies.