Support » Plugin: WooCommerce » Show product description on shop page IF it has this categories

  • Resolved aaroncabanas

    (@aaroncabanas)


    Hi!

    I wanted to show my products description under the title on shop page, which i’ve done like this on functions.php and it works great:

    add_action( 'woocommerce_after_shop_loop_item', 'woo_show_excerpt_shop_page', 5 );
    	function woo_show_excerpt_shop_page() {
    		global $product;
    
    		?>
            <div itemprop="description">
                <?php echo apply_filters( 'the_content', $product->post->post_content ) ?>
            </div>
    	<?php
    }

    And now I would like to show that ONLY if the product is from a certain category (could be in 12 of them, but not in the rest), in which i’ve tried to add this but it is not working:

    if ( is_product() && has_term( 'my_category') ) { 
    	add_action( 'woocommerce_after_shop_loop_item', 'woo_show_excerpt_shop_page', 5 );
    		function woo_show_excerpt_shop_page() {
    			global $product;
    
    			?>
    			<div itemprop="description">
    				<?php echo apply_filters( 'the_content', $product->post->post_content ) ?>
    			</div>
    		<?php
    	}
    }

    If I am able to do it someway I would really appreciate some help with it, and also adding more possible categories in the if condition (as on OR not AND).

    Thank you in advanced!

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

Viewing 2 replies - 1 through 2 (of 2 total)
  • Plugin Support RK a11n

    (@riaanknoetze)

    Hi there,

    This is a fairly complex development topic. I’m going to leave it open for a bit to see if anyone is able to chime in to help you out.

    I can also recommend the WooCommerce Developer Resources Portal for resources on developing for WooCommerce.

    You can also visit the WooCommerce Facebook group or the #developers channel of the WooCommerce Community Slack. We’re lucky to have a great community of open-source developers for WooCommerce, and many of our developers hang out there, as well.

    Thread Starter aaroncabanas

    (@aaroncabanas)

    At the end I figured it out seeing some other examples and worked out for me this way:

    add_action( 'woocommerce_after_shop_loop_item', 'woo_show_excerpt_shop_page', 5 );
    	function woo_show_excerpt_shop_page() {
    		global $product;
    	
    		if (!has_term( 'productos', 'product_cat', $product->get_id())) {
    			?>
    				<div itemprop="description">
    					<?php echo apply_filters( 'the_content', $product->post->post_content ) ?>
    				</div>
    			<?php
    		}
    		elseif (has_term( 'productos', 'product_cat', $product->get_id())) {
    			$tag_count = sizeof( get_the_terms( $post->ID, 'product_tag' ));
       			echo $product->get_tags( ', ', '<span class="tagged_as">' . _n( 'Tag:', 'Tags:', $tag_count, 'woocommerce' ) . ' ', '.</span>' );
    		}
    }
Viewing 2 replies - 1 through 2 (of 2 total)
  • The topic ‘Show product description on shop page IF it has this categories’ is closed to new replies.