D
D
Dmitry2016-09-17 07:09:56
PHP
Dmitry, 2016-09-17 07:09:56

Different templates for different WooCommerce product categories?

Need to make a different sidebar menu for different categories on WooCommerce .

For example:

Product category page #1

<ul>
   <li>Пункт 1</li>
   <li>Пункт 2</li>
</ul>


Product category page #2

<ul>
   <li>Пункт 3</li>
   <li>Пункт 4</li>
</ul>


Or just somehow make different templates, and inserting a menu for each is no longer a problem.

Answer the question

In order to leave comments, you need to log in

3 answer(s)
N
Nikitos08, 2016-10-07
@Nikitos08

You can check the category and display the sidebar you need for it. If there are more categories, elseif can be used.

global $post;

$tags = get_the_terms( $post->ID, 'product_cat' );

foreach ( $tags as $tag ) $tags[] = $tag->slug;

if ( in_array( 'cat-name', $tags ))  {
dynamic_sidebar( 'cat-name-sidebar' );
}
else {
dynamic_sidebar( 'other-sidebar' );
}

?>

X
xtala zen, 2016-09-17
@xtala

Different categories should respectively have unique classes applied to elements. You need to explore the elements of interest in the browser and understand which unique class is applied to a certain category, depending on the active one, then write styles for these classes. The difficulty is to understand which class is applied to the elements depending on the category, because Wordpress assigns multiclasses to the generated html markup.

D
Denis Yanchevsky, 2016-09-17
@deniscopro

There are plugins that allow you to customize widgets so that they only appear on certain pages, such as Dynamic Widgets or Widget Logic . If they do not fit, then you can look for similar ones in the plugin directory .

Didn't find what you were looking for?

Ask your question

Ask a Question

731 491 924 answers to any question