• Is it possible to change the Default product sorting setting from Custom Ordering + Name to Custom Ordering + Price?

    Thanks

Viewing 7 replies - 1 through 7 (of 7 total)
  • Plugin Contributor Mike Jolley

    (@mikejolley)

    You can add or change sorting options with code – see https://docs.woocommerce.com/document/custom-sorting-options-ascdesc/

    Thread Starter seank123

    (@seank123)

    Thanks Mike – will have a loo at that.

    Will this allow me to set add a new default ordering – or override whatever is set in the admin?

    Plugin Contributor Mike Jolley

    (@mikejolley)

    Both; you can add/review other sorting methods.

    Thread Starter seank123

    (@seank123)

    I have:

    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 ( 'new_default_list' == $orderby_value ) {
    		$args['orderby'] = 'menu_order price';
    		$args['order'] = 'asc';
    		$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['new_default_list'] = 'Menu Order + Price';
    	return $sortby;
    }

    It’s grouping the products by Menu Order but not then by price – am I doing multiple options right? – $args[‘orderby’] = ‘menu_order price’;

    Thanks

    Plugin Contributor Mike Jolley

    (@mikejolley)

    Well what are you expecting I should ask? Price sorting will only take effect if the products have the SAME menu order defined.

    Thread Starter seank123

    (@seank123)

    Hi Mike

    Yes, I’ve changed the menu order on products in one category:

    In the first image (hoodies) they all have a menu order of 0 but are still sorting randomly (if I refresh the page I get them in a different order)

    sorting 1

    In this one I have set different menu orders to the products – for example the coats to 4 and the bags to 5 – it sorts them out into the menu order values OK but as you can see, the prices are appearing randomly!

    sorting 2

    Thanks

    0
    down vote
    favorite
    I have created custom sorting option by stock date (which means when I change the status outstock to instock) it will give the product list by modified date. I got the list by using this code

    **$

    args[‘orderby’] = array( ‘meta_value_num’ => ‘DESC’, ‘title’ => ‘ASC’ );
    $args[‘meta_key’] = ‘_stock’;
    **

    I would like to sort bu stock update with menu_order, so I tried this

    **

    $args[‘orderby’] = array( ‘meta_value_num’ => ‘DESC’, ‘title’ => ‘ASC’, ‘menu_order’ => ‘ASC’ );
    $args[‘meta_key’] = ‘_stock’;
    **

    It doesn’t list properly , any one can help me please. It would be appriciated.

Viewing 7 replies - 1 through 7 (of 7 total)

The topic ‘Sort products by Custom Ordering + Price’ is closed to new replies.