[Resolved] Custom category description woocommerce_after_single_product

Home Forums Support [Resolved] Custom category description woocommerce_after_single_product

Home Forums Support Custom category description woocommerce_after_single_product

Viewing 7 posts - 1 through 7 (of 7 total)
  • Author
    Posts
  • #701422
    Ivan Cazorla

    Hi there,

    I’ve figured out a way to add a second, larger description (after showing the products) in my woocommerce categories using this hook:

    add_action( 'woocommerce_after_main_content', 'my_custom_text', 10 );
     
    function my_custom_text() {
    echo '<h1>My title here</h1><p>Description goes here.</p>';
    }

    I was wondering if I can make a custom different text for every category in my store, instead of having just one custom text for each one of them. Is that possible?

    Let me know. Thanks!

    GeneratePress 2.1.4
    GP Premium 1.7.2
    #701586
    Leo
    Staff
    Customer Support

    Hi there,

    Sounds like you need some WooCommerce conditional tags:
    https://docs.woocommerce.com/document/conditional-tags/

    Hope this helps!

    #702306
    Ivan Cazorla

    So then I should put in my function the tag of my cateogry like so?

    add_action( 'woocommerce_after_main_content', 'my_custom_text', 10 );
     
    function my_custom_text() {
    if ( is_product_category() ) {
      if ( is_product_category( 'shirts' ) ) {
        echo 'Hi! Take a look at our sweet tshirts below.';
      } else {
        echo 'Hi! Check our our products below.';
      }
    }
    }

    Let’s see if that would work!

    #702318
    Ivan Cazorla

    Hi there, looks like its working! Nice! Thanks.

    But know, do I really need to put all category descriptions inside this snippet hook, or is there an easy way to create a field on the woocommerce category to introduce that text? So that other people can easily modify the text they want to show?

    thanks,

    #702417
    Leo
    Staff
    Customer Support

    You’d have to ask WooCommerce for that.

    You can see that’s it’s not controlled by GP by the link I provided.

    Glad I could help!

    #708416
    Ivan Cazorla

    Yep, I have asked them and I’ll see if I manage to do what I want.

    thanks!!

    #708422
    Leo
    Staff
    Customer Support
Viewing 7 posts - 1 through 7 (of 7 total)
  • You must be logged in to reply to this topic.