mirror of
https://gh.wpcy.net/https://github.com/mainwp/Code-Snippets-Functions.git
synced 2026-04-29 11:32:21 +08:00
15 lines
535 B
Text
15 lines
535 B
Text
add_filter( 'aws_search_results_products', 'aws_search_results_products', 10, 2 );
|
|
function aws_search_results_products( $products, $s ) {
|
|
usort($products, function ($item1, $item2) {
|
|
$product1 = wc_get_product( $item1['id'] );
|
|
$product2 = wc_get_product( $item2['id'] );
|
|
if ( 'outofstock' !== $product1->get_stock_status() ) {
|
|
return -1;
|
|
}
|
|
if ( 'outofstock' !== $product2->get_stock_status() ) {
|
|
return 1;
|
|
}
|
|
return 0;
|
|
});
|
|
return $products;
|
|
}
|