Search code examples
phpwordpresswoocommerceproductcustom-taxonomy

Add a text under specific Woocommerce product category archive page


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


Solution

  • 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.