• Resolved campcraft

    (@campcraft)


    On our website discontinued products have their price removed/set to zero and then we use code in our php file to automatically hide products with no price from the catalogue:

    /* Hide product in catalog when price is 0 or blank*/
    add_action( 'woocommerce_product_query', 'themelocation_product_query' );
    function themelocation_product_query( $q ){
    $meta_query = $q->get( 'meta_query' );
        $meta_query[] = array(
                    'key'       => '_price',
                    'value'     => 0,
                    'compare'   => '>'
                );
    $q->set( 'meta_query', $meta_query );
    }

    These products hidden from the catalogue pages don’t show up on the individual brand pages, as expected with the php code, but the brand link continues to be shown on the a-z brands page and carousel for brands where all the products have been discontinued. We use the the shortcode hide_empty=”true” to remove empty brands from the carousel and a-z brands page but it doesn’t seem to work with this way of hiding products.

    For example Brand A has products product1, product2 and product3. All of the products are currently discontinued and their prices have been removed. Product1, product2 and product3 are hidden from catalogue pages and are hidden on the Brand A brand page, but the Brand A logo and link still remain visible on the brand carousel and main a-z brands page.

    Is there another way to hide ’empty’ brands from the carousel/a-z page?

Viewing 1 replies (of 1 total)
  • Plugin Author quadlayers

    (@quadlayers)

    hello @campcraft
    this is the method our plugin uses to count products in the brand

    public static function count_visible_products( $brand_id ) {
    		$args     = array(
    			'posts_per_page' => -1,
    			'post_type'      => 'product',
    			'tax_query'      => array(
    				array(
    					'taxonomy' => 'pwb-brand',
    					'field'    => 'term_id',
    					'terms'    => $brand_id,
    				),
    				array(
    					'taxonomy' => 'product_visibility',
    					'field'    => 'name',
    					'terms'    => 'exclude-from-catalog',
    					'operator' => 'NOT IN',
    				),
    			),
    		);
    		$wc_query = new \WP_Query( $args );
    
    		return $wc_query->found_posts;
    	}

    you should change product_visibility

    best regards

Viewing 1 replies (of 1 total)

The topic ‘Hide empty brands in carousel and brand page’ is closed to new replies.