WordPress.org

Ready to get started?Download WordPress

Forums

WooCommerce - excelling eCommerce
[resolved] Show if is in a certain category (2 posts)

  1. Chris
    Member
    Posted 1 year ago #

    Hi,
    I am trying to modify a template file in single-product.php to show some text if the product is in a certain category. I am trying to use the is_category_product but cannot seem to get it to work.

    Here is the code I am trying to use:

    <?php if ( is_product_category( '40' )):?>This video will be mailed to you in DVD format.<?php else : ?> This Video will be Delivered Via Instant Download. High Speed Internet Connection Reccommended. <?php endif;?>

    Any suggestions on how to get this to work?
    Thanks so much in advance!

    http://wordpress.org/extend/plugins/woocommerce/

  2. Chris
    Member
    Posted 1 year ago #

    Figured it out....

    <?php
    global $post;
    $terms = wp_get_post_terms( $post->ID, 'product_cat' );
    foreach ( $terms as $term ) $categories[] = $term->slug;
    
    if ( in_array( 'digital-downloads', $categories ) ) {
      echo 'This Video will be Delivered Via Instant Download.  High Speed Internet Connection Reccommended.';
    } else {
      echo 'This video will be mailed to you in DVD format.';
    } ?>

    Found the answer here:

Topic Closed

This topic has been closed to new replies.

About this Plugin

About this Topic