Categories

Featured templates

Woocommerce. How to set random order for products

Jack Martins November 18, 2015
Rating: 5.0/5. From 3 votes.
Please wait...

This tutorial provides a description of how to set random order for products in Woocommerce store.

Woocommerce. How to set random order for products

In order to set random order for products, you should perform the following:

  1. Navigate to the following directory in your cpanel or FTP: wp-content/themes/themeXXXXX/includes, locate a custom-function.php file, and click an Edit button (or edit it with the help of a text editor):

    Woocommerce._How_to_set_random_order_for_products
  2. Paste the following piece of code to the bottom of the file before the last ?>:

    			add_filter( 'woocommerce_get_catalog_ordering_args', 'custom_woocommerce_get_catalog_ordering_args' );
    			
    			function custom_woocommerce_get_catalog_ordering_args( $args ) {
    			$orderby_value = isset( $_GET['orderby'] ) ? woocommerce_clean( $_GET['orderby'] ) : apply_filters( 'woocommerce_default_catalog_orderby', get_option( 'woocommerce_default_catalog_orderby' ) );
    			
    			if ( 'random_list' == $orderby_value ) {
    			$args['orderby'] = 'rand';
    			$args['order'] = '';
    			$args['meta_key'] = '';
    			}
    			return $args;
    			}
    			
    			add_filter( 'woocommerce_default_catalog_orderby_options', 'custom_woocommerce_catalog_orderby' );
    			add_filter( 'woocommerce_catalog_orderby', 'custom_woocommerce_catalog_orderby' );
    			
    			function custom_woocommerce_catalog_orderby( $sortby ) {
    			$sortby['random_list'] = 'Random';
    			return $sortby;
    			}
    		
    Woocommerce._How_to_set_random_order_for_products1
  3. Save the changes and navigate to the following directory in your WooCommerce Settings: Products–>Display:

    Woocommerce._How_to_set_random_order_for_products2
  4. Check out the Random option under Default Product Sorting directory:

    Woocommerce._How_to_set_random_order_for_products4

Feel free to check the detailed video tutorial below:

Woocommerce. How to set random order for products
This entry was posted in WooCommerce Tutorials and tagged order, product, random, WooCommerce. Bookmark the permalink.

Submit a ticket

If you are still unable to find a sufficient tutorial regarding your issue please use the following link to submit a request to our technical support team. We'll provide you with our help and assistance within next 24 hours: Submit a ticket