• Resolved tabrizi

    (@tabrizi)


    Hello,

    I am unfortunately a little helpless.

    We sell rugs on our website and are now starting to add rugs from other rug dealers to our website as well.

    However, we don’t want the first rugs to be the newest rugs (the rugs from the other dealers).

    It would be good if these are somehow mixed.

    We use the filter plugin “Product Filter by WooBeWoo” which works really great for us.

    I added a snippet the other day that shuffled the order of all products:

    add_action( ‘pre_get_posts’, ‘shop_default_orderby_rand’ );
    function shop_default_orderby_rand( $query ) {
    if ( is_shop() && ( ! isset($_GET[‘orderby’]) || ‘menu_order’ === $_GET[‘orderby’] ) ) {
    $query->set( ‘orderby’, ‘rand’ );
    }
    }

    The problem here is that when you use filters and you open the next product page in the catalog, again the products are shuffled and so you see some products that you have already seen on the page before, or sometimes products are not shown at all because they are randomly selected.

    Is there a better solution here?

    I also tried to export all products and randomly generate the product IDs in Excel and then upload them again and update the products, but unfortunately this does not work, because the product is of course not found if the ID has been changed…

    I hope someone has a good suggestion.

    Thanks in advance.

    The page I need help with: [log in to see the link]

Viewing 1 replies (of 1 total)
  • Plugin Support mouli a11n

    (@mouli)

    @tabrizi
    Nice work with the snippet etc 🙂
    It may be that you can achieve what you want using the inbuilt sort options available in WooCommerce.
    If you go to Appearance ➔ Customize ➔ WooCommerce ➔ Product Catalogue you can select a few sort options there, including Custom ordering.
    With that set, you can then use the Sorting tab under Products ➔ All products to drag and drop the products into the order that you want.
    You can also sort only within a category by filtering the list suing the Select a Category filter at the top of the list.
    Currently, random sorting is not a default offering, and if you use and Action such as in your code, you may well see duplication across pagination since each page calls the same action on load.
    One solution might be finding an existing plugin, or code snippet that works around this issue.
    I searched for WooCommerce random product sort and found some useful options returned.
    I hope that helps.

Viewing 1 replies (of 1 total)

The topic ‘Change Product order’ is closed to new replies.