To display lists of WooCommerce products, WooCommerce now only gives you a single product shortcode as of WooCommerce 3.2 (previously, you had separate shortcodes for featured products, best-selling products, etc.).
However, while there’s only a single base shortcode now, you get a lot of different shortcode modifiers to control which products to display, including options to highlight featured products, sale products, best-selling products, recent products, and more.
The base shortcode is [products], but you can then add more options to control exactly which products to display:
- limit – how many products to display. Or set “-1” to list all products.
- columns – how many columns to divide your grid into.
- paginate – true or false to turn pagination on.
- orderby – how to order products – date, id, menu_order, popularity, rand, rating, or title.
- skus – show specific product SKUs.
- category – show products from one or more categories.
- tag – show products from one or more tags.
- order – ASC or DESC order based on orderby.
- class – add an HTML wrapper with a custom CSS class.
- on_sale – only retrieve on-sale products.
- best_selling – only retrieve best-selling products.
- top-rated – only retrieve top-rated products.
You’ll also get more detailed parameters to target specific types of products:
- attribute – retrieve products with a certain attribute slug.
- terms – comma-separated list of terms to use with attribute
- terms_operator – use it to add operators like AND, IN, or NOT IN. For example, you could require products to contain two attributes by using AND.
- tag_operator – the same thing but for tags.
- cat_operator – the same thing but for categories.
- visibility – display products based on their visibility status – visible, catalog, search, hidden, featured.
- ids – display specific products by adding their product IDs
Because this is the most versatile shortcode, we’ll go through a few different examples of how to use the products shortcode to highlight specific types of products.
Example #1: Display the six best-selling products in a three-column grid:
[products limit=”6″ columns=”3″ best_selling=”true” ]
Keep reading the article at Elementor Blog. The article was originally written by Sergei Davidov on 2021-05-10 07:45:41.
The article was hand-picked and curated for you by the Editorial Team of WP Archives.
This article was written by Sergei Davidov and originally published on Elementor Blog.