- Web templates
- E-commerce Templates
- CMS & Blog Templates
- Facebook Templates
- Website Builders
Woocommerce. How to set random order for products
November 18, 2015
This tutorial provides a description of how to set random order for products in Woocommerce store.
Woocommerce. How to set random order for productsIn order to set random order for products, you should perform the following:
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):
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; }
Save the changes and navigate to the following directory in your WooCommerce Settings: Products–>Display:
Check out the Random option under Default Product Sorting directory:
Feel free to check the detailed video tutorial below:
Woocommerce. How to set random order for products