Home › Forums › Product Support Forums › Ajax Search Pro for WordPress Support › show out of stock label in results › Reply To: show out of stock label in results
May 20, 2020 at 7:04 pm
#27471
Participant
Hi ernst,
quick question about the following code. we have products in backorder that
load below the products that are instock. i would like it to function only if it is out of stock.
// —- Ajax SEARCH PRO -put to bottom —-
add_filter(‘asp_results’, ‘asp_order_out_of_scock’, 10, 1);
function asp_order_out_of_scock($results) {
$first = array();
$last = array();
foreach ( $results as $k => &$r ) {
if ( get_post_meta($r->id, ‘_stock_status’, true) == ‘instock’ ) {
$first[] = $r;
} else {
$last[] = $r;
}
}
return array_merge($first, $last);
}