So I have a super simple Woocommerce shortcode [product_categories], It's supposed to show product categories from the shop.
It does this job perfectly if I put it inside the contents of a page as such: [product_categories].
However, if I put the same thing into the template directly it suddenly returns the first post of current category? What?!
So in my template I have only these two rows:
<?php echo do_shortcode('[product categories]'); // this returns a single product which is wrong and totally weird ?>
<?php the_content(); // this returns the categories as intended ?>
I never knew these two methods have some kind of difference. How can I make the shortcode work with the echo way?
[product_category]
or[product_categories]
. Please check if this is the problem here. Example from the official WooCommerce shortcode documentation:[product_categories number="0" parent="0"]
[product_categories]
is working, it should work here as well, the other stuff are filter / limit parameters. but good point here : "_" jussi if you've copied the code directly from the template file, please recheck if that's the case as you've mentioned that it works but shows only one product.[product_categories]
is working. But if the shortcode[product categories]
is used, this will show a single product. Because[product]
is just a shortcode to show products. To show the product categories itself[product_categories]
should be used. It seems that @Jussi has just forgot the underscore in his shortcode.;
while coding, i recommend you should always copy the shortcode from the available shortcode list to avoid these minor mistakes...