This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
// Add a new sorting option for pushing out-of-stock products last | |
add_filter( 'woocommerce_get_catalog_ordering_args', 'custom_sort_out_of_stock_last', 9999 ); | |
function custom_sort_out_of_stock_last( $args ) { | |
// Check if the custom sorting option is selected | |
if ( isset( $_GET['orderby'] ) && $_GET['orderby'] === 'instock_last' ) { | |
$args['orderby'] = 'meta_value'; | |
$args['meta_key'] = '_stock_status'; | |
$args['order'] = 'ASC'; // 'instock' comes before 'outofstock' | |
} |
OlderNewer