• Resolved simon_a6

    (@simon_a6)


    We have built a page for a category (We use a permalink manager to do this), that has VP Bakery at the top, then a shortcode for the category.

    [products category="Tshirts" paginate="yes" per_page="12" orderby="stock"]

    We added a function that enables us to use ‘stock’ as an attribute, but we want it to sort by Stock then Title. Title is built in, so can you add two Orderby elements here?

    We have tried stock+title, and stock title, but it fails.

Viewing 4 replies - 1 through 4 (of 4 total)
  • I suggest reviewing the Advanced Options for this shortcode. I’m not positive you can order_by two fields but you may be able to use another advanced option to achieve the same result.

    https://docs.woocommerce.com/document/woocommerce-product-search/v1/shortcodes/#section-3

    Please let me know how this works for you.

    Thanks

    • This reply was modified 5 years, 12 months ago by Phillip C. a11n. Reason: Added link to documentation
    Thread Starter simon_a6

    (@simon_a6)

    I don’t see one there related to stock.
    We just want out of stock pushed to the end, and doing it with a shortcode.

    Hello,

    I apologize, I believe I misunderstood your original request. I think if you have used customization to add stock to your sortable attributes then it should be available for use in the order_by attribute in the shortcode reference I supplied in my last message. Please try the following code block in your category page and see if it organizes your products as expected:

    [products category="tshirts" paginate="yes" per_page="12" order_by="stock, title"]

    There are a couple of things I would like to point out about the code above as it compares to your original shortcode because I see a couple of things that may seem small but could have an impact. First, double check your category slug. In your code you show category="Tshirts" but slugs can’t have capitalization. If it works, awesome, but please check your category slug by going to WP Admin → Products → Category → Tshirts. Second, in your code you used the attribute orderby but the documentation shows you should be using order_by. That underscore is vital. Otherwise, WordPress and WooCommerce will just ignore it and the order you are trying to set with it.

    If the code snippet I provided doesn’t work, try reordering the order_by attributes to “title, stock”. If that doesn’t work try just using “stock” by itself. You may find that the page will sort by title by default then apply the “stock” sorting as well.

    Please give it a try and let me know how it works for you.

    Thanks!

    • This reply was modified 5 years, 11 months ago by Phillip C. a11n. Reason: formatting
    • This reply was modified 5 years, 11 months ago by Phillip C. a11n. Reason: Formatting
    Plugin Support Steve E.a11n

    (@woosteve)

    Automattic Happiness Engineer

    There are no recent responses to this thread so hopefully the above helped.

    I’ll mark this as resolved. Please feel free to open a new thread if you have any further questions.

Viewing 4 replies - 1 through 4 (of 4 total)
  • The topic ‘Can you set Shortcodes to order by TWO Attributes?’ is closed to new replies.