Support » Plugin: WooCommerce » Custom sorting options (asc/desc)

  • Resolved pbraun

    (@pbraun)


    Hi,

    I’ve added random ordering option in Appearence < Customize < WC < Product Catalog < Default Product sorting for my product lists using this code

    /**
     * Add custom sorting options (asc/desc)
     */
    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'] ) ? wc_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;
    }

    It does add the options but choosing this options does not change product order to random 🙁
    Any thoughts on this ? Thanks a lot

    • This topic was modified 11 months, 2 weeks ago by pbraun.
    • This topic was modified 11 months, 2 weeks ago by pbraun.

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

Viewing 4 replies - 1 through 4 (of 4 total)
Viewing 4 replies - 1 through 4 (of 4 total)
  • The topic ‘Custom sorting options (asc/desc)’ is closed to new replies.