• Resolved debrecenibalazs

    (@debrecenibalazs)


    Hi Guys,

    First things first I am in love with the plugin,
    Another problem occured when I am trying to exclude one specific page from the BBloomer’s Stock forst snippet.

    The snippet I am using the following:

    if ( is_page( 499 ) ) {
    return;
    }

    add_filter( ‘woocommerce_get_catalog_ordering_args’, ‘bbloomer_first_sort_by_stock_amount’, 9999 );

    function bbloomer_first_sort_by_stock_amount( $args ) {
    $args[‘orderby’] = ‘meta_value’;
    $args[‘order’] = ‘ASC’;
    $args[‘meta_key’] = ‘_stock_status’;
    return $args;

    }

    The purpose of this tiny snippet is to sort the in-stock products first and exclude the main page( ID:499) from the code itself.

    Maybe I am doing something wrong, but i would apreciate a little help ??

    Tkae care and have a node weekend!

    The page I need help with: [log in to see the link]

Viewing 4 replies - 1 through 4 (of 4 total)
  • Plugin Author Shea Bunge

    (@bungeshea)

    Hi @debrecenibalazs,

    Have you tried placing the is_page check within the funcion hook itself?

    add_filter( 'woocommerce_get_catalog_ordering_args', function ( $args ) {
    	if ( is_page( 499 ) ) {
    		return $args
    	}
    
    	$args['orderby'] = 'meta_value';
    	$args['order'] = 'ASC';
    	$args['meta_key'] = '_stock_status';
    	return $args;
    }, 9999 );
    Thread Starter debrecenibalazs

    (@debrecenibalazs)

    Dear Shea,

    thank you very much for your kind answer.

    I have added the code but my WP does not like it. It popped up a Fatal Error which I dont understand why – the code itself looks very fine for me.

    Plugin Author Shea Bunge

    (@bungeshea)

    My apologies @debrecenibalazs, it looks like a rather crucial character was missing from my post:

    add_filter( 'woocommerce_get_catalog_ordering_args', function ( $args ) {
    	if ( is_page( 499 ) ) {
    		return $args;
    	}
    
    	$args['orderby'] = 'meta_value';
    	$args['order'] = 'ASC';
    	$args['meta_key'] = '_stock_status';
    	return $args;
    }, 9999 );

    @debrecenibalazs would have been nice to reference where you got the snippet from (https://www.businessbloomer.com/woocommerce-show-in-stock-products-first-shop/). Thank you

Viewing 4 replies - 1 through 4 (of 4 total)
  • The topic ‘Exclude PHP snippet on a specific page’ is closed to new replies.