• Resolved killerdog

    (@killerdog)


    First off, great plugin! Very useful indeed. Thanks for making it available!

    So, @jtree5757 previously mentioned in this forum, that the random products feature isn’t working correctly with pagination, since it resets at every new page. Which means customers won’t effectively be able to see all products using this sort mode unless pagination is avoided. This has effected us as well.

    Couldn’t this be fixed by utilizing the user’s unique session id as a randomize key? Or, maybe by passing a randomize key as a user cookie? This way, the randomized product list is static for the full user session, and automatically reset when a new session is created later on.

    Just my ten cents here, as we really love the idea of using the random product list, even with pagination! Thanks again!

    https://wordpress.org/plugins/woocommerce-extra-product-sorting-options/

Viewing 4 replies - 1 through 4 (of 4 total)
  • Plugin Author Beka Rice

    (@bekarice)

    Hey @killerdog, you could definitely work pagination if you used a seed for each user. However, as this plugin using the built in WooCommerce filters for sorting options, it’s pretty limited in what we can do aside from passing in a custom sorting argument, and thus randomized sorting pagination can’t be implemented here. This was intended originally for small product catalogs.

    For the regular WordPress sorting filters, the entire WP Query object is passed into filters, so you can modify it to seed & randomize items. With WooCommerce, we’re using a pre-built query and filtering only its arguments, so we can’t really do this in a simple way.

    If you wanted to do this with a customized bit of code, you could replace the WooCommerce sorting dropdown completely yourself and use your own query for randomized sorting, I’ve found this tutorial helpful in the past.

    Sorry I don’t have better news for you here. Cheers!

    Hey there – I got notified about this because you linked to my blog – thanks Beka! 🙂

    Anyway – I thought I’d jump in here quickly to let you know that as of WordPress 4.5, that snippet in my post will be unnecessary (although it will still work of course). The reason for this is that in v4.5+ you will be able to specify a seed value for the random ordering from directly within the WP_Query args. So you can set your orderby parameter to look like this: rand(123) (where ‘123’ is your seed value) – that will achieve the same results as the solution in my post, but using much less code. You’ll still need to use the session to store the seed value, but you won’t need to use the posts_orderby filter anymore. Pretty neat!

    And that concludes your friendly WordPress tip for the day 🙂

    Plugin Author Beka Rice

    (@bekarice)

    thanks for the extra info Hugh! Did not see that update myself, definitely helpful 🙂

    Hi all and thanks Hugh for this awesome (and much needed) contribution. I’m chiming in to add a little something to this. In my case, I wanted to have a random order that would change every day, but would remain the same within each given day. So, the solution to this (combined with Hugh’s contribution) would be 'orderby' => 'rand('.date('Ymd').')'. I this scenario, there’s no need to store anything to the session cookie.

Viewing 4 replies - 1 through 4 (of 4 total)
  • The topic ‘Random sort order even with pagination’ is closed to new replies.