0

I wanted to have some additional text below the displayed products on the product category page on my website. I didn't know how to do this the smart way, so I just shoved some text into the taxonomy-product-cat.php theme file.

Here is the code for that page:

<?php

/**
 *
 * @author      WooThemes
 * @package     WooCommerce/Templates
 * @version     1.6.4
 */

 ?>

<?php get_header( 'shop' ); ?>

<?php do_action( 'woocommerce_before_main_content' ); ?>

<div style="margin-left:645px;"><?php if ( function_exists( 'ADDTOANY_SHARE_SAVE_KIT' ) ) { 
    ADDTOANY_SHARE_SAVE_KIT( array( 'use_current_page' => true ) );
} ?></div>

<?php tf_woocommerce_product_taxonomy_content(); ?>

<div id="prodcatdesc"><div style="padding-top:85px;"><hr><p>My text that I wrote is here.</p></br>
</div></div>

<?php do_action( 'woocommerce_after_main_content' ); ?>

<?php do_action( 'woocommerce_sidebar' ); ?>

<?php get_footer( 'shop' ); ?>

So, this works, but it also adds the text I shoved in there into every product category page on my site. What I am wondering is, how can I constrain the div text I added to only one specific category page?

The theme I am using is Sooperstore if that helps. This little nuisance is stopping me from expanding my entire store :(

Thanks,

0

For Woocommerce product categories, use

<?php if ( is_product_category() ) {

 echo '<div id="prodcatdesc">';

  if ( is_product_category( 'shirts' ) ) {
    echo 'Hi! Take a look at our sweet tshirts below.';

  } elseif ( is_product_category( 'games' ) ) {

    echo 'Hi! Hungry for some gaming?';
  } else {

    echo 'Hi! Check our our products below.';

    echo '</div>';
  }

} ; ?>

Or, for just one,

<?php 

     if ( is_product_category( 'shirts' ) ) {

        echo '<div id="prodcatdesc">';
        echo 'Hi! Take a look at our sweet tshirts below.';
        echo '</div>';
        } ;

 ?>

See https://docs.woocommerce.com/document/conditional-tags/

Put your inline styles, i.e. <div style="padding-top:85px;"><hr><p> in CSS.

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.