I have been working on a plugin based on woocommerce. As a part of this I am trying to list all the category links in a page using a shortcode and I have succeeded in this.
The issue is all the category links with zero products are returning 404 error page where as the link works fine if the category has one or more products. Did anyone face this issue earlier?
Updating with Code:
$args = array('taxonomy' => 'product_cat', 'hide_empty' => false, 'parent' => 0, 'exclude' => 723);
$terms = get_terms('product_cat', $args);
if (!$category instanceof WP_Error) {
foreach ($terms as $term):
?>
<ul class="col-md-3 col-lg-3 col-sm-6 col-xs-6 directory_catblock">
<h3>
<a href="<?php echo site_url() . '/' . $term->slug; ?>"><?php echo $term->name; ?></a>
</h3>
<?php
$args_sub = array('taxonomy' => 'product_cat', 'hide_empty' => false, 'parent' => $term->term_id);
$terms_sub = get_terms('product_cat', $args_sub);
foreach ($terms_sub as $term_sub):
?>
<li>
<a href="<?php echo site_url() . '/' . $term->slug . '/' . $term_sub->slug; ?>"><?php echo $term_sub->name; ?></a>
</li>
<?php endforeach; ?>
</ul>
<?php endforeach;}