Archived topic
Niche theme - Woocommerce : show categories in wc pages
9 replies · Started by Claudia on July 16, 2020
Hi Tom, David and Leo (I don't know if I'm missing someone)
First of all, we really appreciate the work you are doing with GP :-)
To the point, I've tried to find the solution in the forum, but I couldnt. We are running Niche theme, and we'ld like to show the woocommerce product categories in shop pages (shop index, single product, and I any other wc page)
I've checked and we have the "Woocommerce Shop Category Menu" Element enabled (see below). As far as I checked the code is not generated in the html. I don't know what we are doing wrong. Can you help us? Or any idea how to proceed?
Thank you in advance
<?php
$cat_args = array(
'orderby' => 'name',
'order' => 'asc',
'hide_empty' => false,
);
$product_categories = get_terms( 'product_cat', $cat_args );
if ( ! empty( $product_categories ) ) {
echo '<ul class="woo-cat-nav">';
foreach ( $product_categories as $key => $category ) {
printf(
'<li>
<a href="%1$s">
%2$s
</a>
</li>',
get_term_link( $category ),
$category->name
);
}
echo '</ul>';
}
?>
Hook woocommerce_archive_description
Execute PHP YES
Display Rules
- Product Category Archive: All Product Categories
- Product Archive
Hi there,
Lets test if the hook is where it should be.
In your hook code above, just before the <?php add:
<h2>The hook is working</h2>
If that displays on the front end we know the hook is working. Let me know. Then we can look at why the codes conditions aren't being met
Hi David,
Nope, it doesn't display it
That means that either:
1. The Display Rules are not working.
OR
2. The Hook is missing.
Lets test #1 - by adding Entire Site to the Hooks Display Rules.
Let me know.
Ok, adding to display for the entire site didn't work
Now try changing the hook to after_header
Keep the Display Rules as is.
And keep the <h2>The hook is working</h2> in there.
Ok, I've got something :-)
Changing the hook to after_header make it appear in the single product page. Not in the shop page. Even more, it appeared all the categories. You can check by yourself in the provided link
OK - something else must be interfering.
Are you using a Child Theme ? If so can you temporarily disable it.
Next step is to disable any other plugins or custom functions to see if there is a conflict.
SOLVED!
It was the plugin "Productos sin stock" (that orders the WC products with no stock at last position)
Thank you David!
Glad to hear you found the issue.