• Found the following code to hide categories from the Wishlist button. However, nothing happens when I save it.

    if ( ! function_exists( 'yith_wcwl_show_add_to_wishlist_button_exclude_categories' ) ) {
    	function yith_wcwl_show_add_to_wishlist_button_exclude_categories( $show ) {
    		global $product;
    
    		$excluded_categories = array(
    			'gazebos',
    			'pergolas',
                'quote-services',
                'playsetservices',
                'basketball-goals',
                'trampolines',
                'shed-services',
    		);
    		$product_categories = wp_get_post_terms( $product->get_id(), 'product_cat' );
    		$product_categories = $product_categories ? wp_list_pluck( $product_categories, 'slug' ) : array();
    
    		if ( array_intersect( $excluded_categories, $product_categories ) ) {
    			return false;
    		}
    
    		return $show;
    	}
    	add_filter( 'yith_wcwl_show_add_to_wishlist', 'yith_wcwl_show_add_to_wishlist_button_exclude_categories', 10, 1 );
    }
Viewing 1 replies (of 1 total)
  • Plugin Support Juan Coronel

    (@juaancmendez)

    Hello there,
    we hope you’re doing well!

    In order to achieve what you need, please replace the previous code with this new one:

    if( !function_exists('yith_wcwl_hide_wishlist_button_on_a_specific_category') ) {
        function yith_wcwl_hide_wishlist_button_on_a_specific_category( $template, $wishlist_url, $product_type, $exists ) {
       
        global $product;
       
        if ( $product ) {
       
            $excluded_categories = array(
    			'gazebos',
    			'pergolas',
                'quote-services',
                'playsetservices',
                'basketball-goals',
                'trampolines',
                'shed-services',
    		);
    		$product_categories = wp_get_post_terms( $product->get_id(), 'product_cat' );
    		$product_categories = $product_categories ? wp_list_pluck( $product_categories, 'slug' ) : array();
    
    		if ( array_intersect( $excluded_categories, $product_categories ) ) {
    			return '';
    		}
       
        }
       
        return $template;
        }
       
          add_filter( 'yith_wcwl_add_to_wishlisth_button_html', 'yith_wcwl_hide_wishlist_button_on_a_specific_category', 99, 4 );
    }

    Check it out and tell us if it works well for you, please.

    Best regards.

Viewing 1 replies (of 1 total)
  • The topic ‘Hide Categories’ is closed to new replies.