Support » Plugin: YITH WooCommerce Best Sellers » Exclude specific product

  • Resolved perfectword7

    (@perfectword7)


    Hi. Thanks for all the great plugins!

    How can I exclude a specific product from the best sellers list?

    Thank you!

Viewing 7 replies - 1 through 7 (of 7 total)
  • Plugin Author YITHEMES

    (@yithemes)

    Hi there,

    in best seller plugin you find this hook:

    apply_filters( 'yith_wcbs_remove_best_seller', false, $product, $bs_product );

    you can use it to exclude a specific product to best seller.

    perfectword7

    (@perfectword7)

    I have tried to figure out how to implement this, but I failed.

    Could you please provide the code for an example of what I’m supposed to put in my child theme’s function.php file to exclude a specific product from the best sellers list?

    Thank you very much.

    Plugin Author YITHEMES

    (@yithemes)

    Hi there,

    yes, in example this code remove from bestseller the products with the a specif ids (15, 75 and 321 in my example):

    add_filter( 'yith_wcbs_remove_best_seller', 'yith_wcbs_remove_best_seller', 10, 3 );
    
    if( ! function_exists( 'yith_wcbs_remove_best_seller' ) ){
    	function yith_wcbs_remove_best_seller( $remove, $product, $bs_product  ){
    		if( $product instanceof WC_Product ){
    			$product_ids_to_remove = array( 15, 75, 321 );
    
    			if( in_array( $product->get_id(), $product_ids_to_remove ) ){
    				$remove = true;
    			}	
    		}
    		
    		return $remove;
    	}
    }
    perfectword7

    (@perfectword7)

    That worked perfectly! Thank you so much.

    The only other thing I had to do was increase the number of products to show by one, so bring it back to the total number of products I was originally showing.

    Thanks again!

    Plugin Author YITHEMES

    (@yithemes)

    You are welcome!

    The only other thing I had to do was increase the number of products to show by one, so bring it back to the total number of products I was originally showing.

    We’re afraid we don’t understand well your point.
    Please could you provide us with further information about the goal you want to achieve?

    perfectword7

    (@perfectword7)

    Before I used your code to remove the specific product, we had 10 items in our best seller list.

    After I used your code, there were only 9 items in the best seller list. Your code excluded the specific product, but also reduced the number of items in the best seller list by 1.

    So, I just increased the “number of products to show” in the plugin settings to 11, and then the best seller list displayed 10 products again, as was originally showing.

    All is well. Great solution. Thank you.

    Plugin Author YITHEMES

    (@yithemes)

    Hi there,
    happy to read that your issue is fixed 🙂
    Don’t hesitate to contact us again if you need additional support!

Viewing 7 replies - 1 through 7 (of 7 total)
  • The topic ‘Exclude specific product’ is closed to new replies.