3

I would like to show text under Shop page main content. Different text for different categories.

I am aware of showing category description on the Shop page for each category but this is already in use.

Right now I am this far but it does not seem to work in the Child theme functions.php

if ( is_category( 'category1' ) ) {
    function add_my_text() {
        print '<p>This is my extra text.</p>';
      }     
    add_action( 'woocommerce_after_main_content', 'add_my_text' );
}

Will be thankful if anyone knows how to improve this function

LoicTheAztec
  • 184,753
  • 20
  • 224
  • 275

2 Answers2

1

The Wordpress conditional function is_category() doesn't work with Woocommerce product categories which are a custom taxonomy. Instead use Woocommerce conditional tag is_product_category() inside your hooked function like:

add_action( 'woocommerce_after_main_content', 'add_my_text' );
function add_my_text() {
    if ( is_product_category( 'category1' ) ) {
        echo '<p>This is my extra text.</p>';
    }    
}

Code goes on function.php file of your active child theme (or active theme). It should works.

LoicTheAztec
  • 184,753
  • 20
  • 224
  • 275
1

Thrilled I found this answer. Was struggling mightily to add content based on a custom taxonomy created with Custom Post Type UI. In case anyone else needs to know, you don't have to change permalinks or anything silly like that. Simple modification of LoicTheAztec's answer above does the trick.

add_action( 'woocommerce_product_meta_end', 'add_my_text' );
function add_my_text() {
    if ( wc_get_product_class( $class = 'taxonomy-term' ) ) {
        echo '<h2>IT WORKS!!!</h2>';
    }    
}

If you want to insert content into a different place on the page, choose a different hook from this very helpful WooCommerce Visual Hook Guide.

Hope this saves somebody else 9 hours :)