• Resolved WildFire

    (@wildfire9859)


    hello
    can you please add an option to display the product that are in stock at the top of the results and the products that are out of stock below them . i do understand there is an option to exclude out of stock products but that’s not my intention i would just appreciate if you can add an option to display the products that are in stock at the top of the results.
    thank you in advance

Viewing 2 replies - 1 through 2 (of 2 total)
  • Kris

    (@c0nst)

    Hi @wildfire9859!

    With this code snippet, you can promote in-stock products.

    add_filter( 'dgwt/wcas/search_results/product/score', function( $score, $keyword, $product_id ) {
    	$woo_product = wc_get_product( $product_id );
    
    	if ( ! is_object( $woo_product ) ) {
    		return $score;
    	}
    
    	if ( $woo_product->is_in_stock() ) {
    		$score += 200;
    	}
    
    	return $score;
    }, 10, 3 );

    You have two ways to add this code to your theme:

    1. Open the functions.php in your child theme and add the code at the end.
    2. or install the?Code Snippets?plugin and apply this code as a snippet.

    Regards,
    Kris

    Thread Starter WildFire

    (@wildfire9859)

    thank you very much
    i appreciate it

Viewing 2 replies - 1 through 2 (of 2 total)
  • The topic ‘feature request’ is closed to new replies.