'Modify WooCommerce to consider backorder status as instock

When using the below snippet, WooCommerce would order products based on stock status value:

  1. instock
  2. onbackorder
  3. outofstock
add_filter( 'woocommerce_get_catalog_ordering_args', 'shop_sort_by_stock_amount', 9999 );
 
function shop_sort_by_stock_amount( $args ) {
   $args['orderby'] = 'meta_value';
   $args['meta_key'] = '_stock_status';
   return $args;
}

However, I want WooCommerce to consider onbackorder as instock so the position orderby remains the same.



Sources

This article follows the attribution requirements of Stack Overflow and is licensed under CC BY-SA 3.0.

Source: Stack Overflow

Solution Source