Skip to content

Instantly share code, notes, and snippets.

Show Gist options
  • Star 1 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save felipeelia/906a382ec174b8113fe656897a2f0e95 to your computer and use it in GitHub Desktop.
Save felipeelia/906a382ec174b8113fe656897a2f0e95 to your computer and use it in GitHub Desktop.
WooCommerce - Change default catalog sort order to stock status and date
/**
* This code should be added to functions.php of your theme
**/
function my_woocommerce_catalog_orderby( $args ) {
$args['meta_key'] = '_stock_status';
$args['orderby'] = array( 'meta_value' => 'ASC', 'date' => 'DESC' );
return $args;
}
add_filter( 'woocommerce_get_catalog_ordering_args', 'my_woocommerce_catalog_orderby' );
@k-msalehi
Copy link

works in 2021

@teleonlineorg
Copy link

Works in 2023

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment