Hide out of stock (only in resultbox)

Home Forums Product Support Forums Ajax Search Pro for WordPress Support Hide out of stock (only in resultbox)

This topic contains 13 replies, has 2 voices, and was last updated by

 
Participant
1 year, 11 months ago.

Viewing 14 posts - 1 through 14 (of 14 total)
  • Author
    Posts
  • #25550

    Participant

    Hi

    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.

    Attachments:
    You must be logged in to view attached files.
    #25569

    Hi,

    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;
    }
    Best,
    Ernest Marcinko

    If you like my products, don't forget to rate them on codecanyon :)


    #25762

    Participant

    Hi 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;
    }

    #25767

    Participant

    example when somebody fills in (see example) the result with “uitverkocht” which means sold out should be on the bottom.

    Attachments:
    You must be logged in to view attached files.
    #25769

    Actually, this might be possible via a configuration. Try chaging the ordering like so: https://i.imgur.com/uMn3lWG.png

    Best,
    Ernest Marcinko

    If you like my products, don't forget to rate them on codecanyon :)


    #25772

    Participant

    Hi Ernst,

    great. this indeed fixed that. sadly, id does create new one. check image.

    the book title isn’t populating with this setting.

    https://www.royaljongbloed.com/nl/product/kom-en-zie/

    Attachments:
    You must be logged in to view attached files.
    #25779

    Hi,

    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.

    Best,
    Ernest Marcinko

    If you like my products, don't forget to rate them on codecanyon :)


    #25780

    Hi,

    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.

    Best,
    Ernest Marcinko

    If you like my products, don't forget to rate them on codecanyon :)


    #25788

    Participant

    Hi 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.

    #25800

    Participant
    You cannot access this content.
    #25802

    Participant
    You cannot access this content.
    #25804

    Participant

    Hi 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);
    }

    #25808

    Hi,

    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.

    Best,
    Ernest Marcinko

    If you like my products, don't forget to rate them on codecanyon :)


    #25809

    Participant

    absolutly love you!!!! this works like a charm!

    my solution did not work on “max lucado” since the title was provided with max lucado

    Attachments:
    You must be logged in to view attached files.
Viewing 14 posts - 1 through 14 (of 14 total)

You must be logged in to reply to this topic.