Woocommerce is one of the top-rated plugins that used to convert any WordPress site into an eCommerce site. It comes with several pre-defined functions. We can use these functions with the help of using shortcodes into any page or post. Woocommerce has all of the essentials shortcodes required for any fully functional shopping site.
Today we will learn about the Woocommerce shortcodes and how to use shortcodes in the shop pages and posts.
How to Use WooCommerce Shortcodes
Woocommerce shortcodes are very easy to use, and you can copy-paste in text editors. for example, if you want to show recent products on the page, you can just simply paste the shortcode [recent_products] on the text editor.
How to display Woocommerce pages by shortcode:
However, When you install the woocommerce plugin, at the initial setup process, Woocommerce automatically creates important pages such as a cart, checkout, my account, order tracking. But, sometimes we failed to complete the setup or for any other reasons, pages do not create themselves automatically. So we can create these 4 pages by using shortcode.
For creating cart page: [woocommerce_cart]
For creating checkout page: [woocommerce_checkout]
My account page: [woocommerce_my_account]
For showing order tacking form: [woocommerce_order_tracking]
How to display products using shortcode in Woocommerce:
We can display products by using the following shortcode:
We can use this shortcode on any page where we want to show the products. We can also use the other attributes with this shortcode.
Limit the Number of Products:
It will limit the products to display only 6 products.
Sorting the product in shortcode:[products limit="6" orderby="date"] or
We can sort the products with following attributes:
- date – sort by published date.
- title – Tsort by the product title. if you do not use any attribute, this one is default.
- id – sort by product id.
- rand – sort randomly
- rating – sort by the product rating.
- menu_order – The Menu Order, if set (lower numbers display first).
- popularity – sort by the number of purchases.
Display by sku or product id
We can show the specific products by using id or sku.[products ids="1, 2, 32, 42,45, 36"] or [products skus="e0031, w0036, b8005, lk8009"]
Modify the layout
We can modify the layout by declaring the columns in shortcode[products ids="1, 2, 32, 42,45, 36" columns="5"]
Others Woocommerce products shorcodes:[products orderby="date" order="Desc"] – for descending order [products orderby="date" order="asc"] – for ascending order [products columns="5" paginate="true"] – for showing pagination [recent_products per_page="6"] – for showing recent products – displays related products. [best_selling_products per_page="5"] – For showing best selling products [top_rated_products per_page="5"] – For displayong top rated products. [product_categories number="0" parent="0"] – to show top level categories. [featured_products per_page="10" columns="5"]– For featured set products
Display an individual product page