I would like to make a shortcode, that can be placed on category pages, for example on the sidebar.
It should display the category’s best selling products.
The only solution that I find is if I specify the category, with slug or id, like below:
[best_selling_products category=”KITCHEN-ACCESSORIES” columns=”1″ per_page=”5″]How can I transform the shortcode to something like this?
[best_selling_products category=”CURRENT-CATEGORY” columns=”1″ per_page=”5″]
2
Answers
Add this to your functions.php
This will create a custom shortcode and you can use it like this:
[custom_best_selling_products columns="1" per_page="5"]
This shortcode will automatically get the category
Add the follows code snippet in your active theme’s functions.php to get best selling products from current
$term
or category page –Add just use woocommerce default shortcode
[best_selling_products columns="1" per_page="5"]
to get the data.