• Resolved bertg

    (@bertg)


    I have been racking my brain looking for a code snippet that would allow me to alter the default sorting so that it would sort all in-stock featured items (by title ASC) first then in-stock items (by title ASC), then out-of-stock feature items (by title ASC), finally by out-of-stock items (by title ASC)

    Current Default Sorting

    • Item 1 (In Stock)
    • Item 2 (Out of Stock)
    • Item 3 (Out of Stock)
    • Item 4 (In Stock)
    • Item 5 (In Stock)(Featured)
    • Item 6 (Out of Stock)(Featured)
    • Desired Default Sorting

    • Item 5 (In Stock)(Featured)
    • Item 1 (In Stock)
    • Item 4 (In Stock)
    • Item 6 (Out of Stock)(Featured)
    • Item 2 (Out of Stock)
    • Item 3 (Out of Stock)
    • I managed to sort by stock status and title (A-Z) with the snippet below.

      add_filter('woocommerce_get_catalog_ordering_args', 'custom_catalog_orderby');
      function custom_catalog_orderby( $args ) {
          $args['meta_key'] = '_stock_status';
          $args['orderby'] = 'meta_value title';
          $args['order'] = 'asc'; 
          return $args;
      }

      How would you include the feature meta_key into the above filter to get the desired sorting outlined above?

      Any insights and/or directions are highly appreciated.

Viewing 2 replies - 1 through 2 (of 2 total)
Viewing 2 replies - 1 through 2 (of 2 total)
  • The topic ‘Changing Default Sorting: Featured (A-Z) First + Stock Status (A-Z) ,’ is closed to new replies.