Khatchik
Khatchik

Reputation: 21

Woocommerce category text

I am trying to upgrade my SEO on my webshop. Anyone knows php could fix this puzzle. How can i fit this in each other?

How does this: is_product_category( 'shirts' ) fit in this:

function woa_content_before_shop() {
    echo "<p>Insert your Content here...</p>";
}

add_action( 'woocommerce_before_shop_loop', 'woa_content_before_shop');

Upvotes: 1

Views: 310

Answers (2)

dzeriho
dzeriho

Reputation: 76

Use this code. Also set your descriptions in Products > Categories.

function woa_content_before_shop() {
    if ( is_product_category() ) {
        global $wp_query;
        $id = $wp_query->get_queried_object_id();
        $desc = term_description( $id, 'product_cat' );
        if ( !empty( $desc ) ) {
            $output = '<p>' . esc_html( $desc ) . '</p>';
            echo $output;
        }
    }
}
add_action( 'woocommerce_before_shop_loop', 'woa_content_before_shop');

Upvotes: 1

hatef
hatef

Reputation: 6199

WordPress conditional tags like is_product_category() can be used to change the displayed content based on the matched condition.

In this case you can use them to change the printed text based on category. You can exploit them in this way:

function woa_content_before_shop()
{
  if ( is_product_category( 'shirts' ) )
  {
    echo "<p>Here are shirts!</p>";
  } 
  else if ( is_product_category( 'games' ) )
  {
    echo "<p>Here are games!</p>";
  } 
  else
  {
    ...
  }
}

add_action( 'woocommerce_before_shop_loop', 'woa_content_before_shop');

Upvotes: 1

Related Questions