Home › Forums › Product Support Forums › Ajax Search Pro for WordPress Support › Hide out of stock (only in resultbox)
- This topic has 13 replies, 2 voices, and was last updated 6 years, 3 months ago by
skempenaar.
-
AuthorPosts
-
January 29, 2020 at 3:13 pm #25550
skempenaar
ParticipantHi
is it possible to hide out of stock products populate in de result dropdown but they are able to find a product that is out of stock?
when hitting the enter or magnify button?cheers.
January 30, 2020 at 5:05 pm #25569Ernest Marcinko
KeymasterHi,
Well, it might be possible via a custom code, but I am not sure.
Try adding this custom code to the functions.php in your theme/child theme directory. Before editing, please make sure to have a full site back-up just in case!
add_filter("asp_query_args", "asp_query_args_change2", 10, 2); function asp_query_args_change2($args, $search_id) { // Reset the post_meta_filter on non-ajax-search if ( $args['_ajax_search'] == false ) $args['post_meta_filter'] = array(); return $args; }February 11, 2020 at 2:42 pm #25762skempenaar
ParticipantHi Ernets,
Thx for your response. looks like this does not work. maybe a different solution could be more fitting.
atm im using the code below to hide out of stock products from the resultbox from ajax search pro.could it be possible that the out of stock items are not hidden but the do appear. but since they are out of stock their relevance is 0. Which results that the show on the bottom of the result box.
// —- Ajax SEARCH PRO – Hide out of stock—-
add_filter( ‘asp_pagepost_results’, ‘asp_stock_status_filter’, 1, 1 );
function asp_stock_status_filter( $pageposts ) {
foreach ($pageposts as $k=>$v) {// Get the stock status
$stock_status = get_post_meta( $v->id, ‘_stock_status’, true);if ( empty($stock_status) || $stock_status == “instock” )
continue;unset($pageposts[$k]);
}return $pageposts;
}February 11, 2020 at 3:53 pm #25767skempenaar
Participantexample when somebody fills in (see example) the result with “uitverkocht” which means sold out should be on the bottom.
February 11, 2020 at 3:56 pm #25769Ernest Marcinko
KeymasterActually, this might be possible via a configuration. Try chaging the ordering like so: https://i.imgur.com/uMn3lWG.png
February 11, 2020 at 4:14 pm #25772skempenaar
ParticipantHi Ernst,
great. this indeed fixed that. sadly, id does create new one. check image.
the book title isn’t populating with this setting.
February 12, 2020 at 11:12 am #25779Ernest Marcinko
KeymasterHi,
That is probably due to the primary ordering taking into account the stock status, and then only the relevance. I don’t think there is any way to prevent that unfortunately.
February 12, 2020 at 11:12 am #25780Ernest Marcinko
KeymasterHi,
That is probably due to the primary ordering taking into account the stock status, and then only the relevance. I don’t think there is any way to prevent that unfortunately.
February 12, 2020 at 1:01 pm #25788skempenaar
ParticipantHi ernst,
yes that’s it indeed. relevance must be primairy and that does fits our needs for the most. stock status as secondary doesn’t do the trick.
its not possible to lower the relevance if a product is out of stock?cheers.
February 13, 2020 at 10:23 am #25800skempenaar
ParticipantYou cannot access this content.
February 13, 2020 at 10:25 am #25802skempenaar
ParticipantYou cannot access this content.
February 13, 2020 at 12:07 pm #25804skempenaar
ParticipantHi Ernst,
found a solution. we add a tag (name of the author) of the book author if the product is in stock. our books are being imported overnight so with the following code our in stock products get reordered in ajax search pro. simply because the tag is present.
function set_author_to_tag($ProductAvailability, $value) {
if($ProductAvailability == ’21’ )
print_r($value);
if($ProductAvailability == ’22’ )
print_r($value);
if($ProductAvailability == ’23’ )
print_r($value);
if($ProductAvailability == ’10’ )
print_r($value);
if($ProductAvailability == ’30’ )
print_r($value);
if($ProductAvailability == ’32’ )
print_r($value);
}
function author_select($ProductAvailability, $type, $data){
$roles = [‘auteur’ => ‘A01′,’illustrator’ => ‘A12′,’vertaler’ => ‘B06′,’redacteur’ => ‘B01’,];
$currentRole = $roles[$type];
$contributors = [];foreach ($data as $key => $contributor) {
$role = $contributor[0];
$first_name = $contributor[1];
$prefix = $contributor[2];
$last_name = $contributor[3];if ($role === $currentRole) {
$prefix = ($prefix) ? $prefix . ‘ ‘ : ”;// We have a winner
$contributors[$first_name . ‘ ‘ . $prefix . $last_name . ‘; ‘] = $key;
}
}
$value = implode(array_flip($contributors));
set_author_to_tag($ProductAvailability, $value);
}February 13, 2020 at 4:48 pm #25808Ernest Marcinko
KeymasterHi,
That works, but I actually may have figured out something to push them to the 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); }I have not tested this, so please be careful.
February 13, 2020 at 4:51 pm #25809skempenaar
Participantabsolutly love you!!!! this works like a charm!
my solution did not work on “max lucado” since the title was provided with max lucado
-
AuthorPosts
- You must be logged in to reply to this topic.