In WooCommerce, you can use short code to integrate custom shipping experience in to your design flow. Have a look at what WooCommerce offers out of the box.
Products
Note: Since version 3.6, WooCommerce Core includes several product blocks. These are easier to configure than shortcodes, so if you are using the WordPress block editor, you may want to read more about WooCommerce Blocks first.
The [products]
shortcode is one of our most robust shortcodes, which can replace various other strings used in earlier versions of WooCommerce.
The [products]
shortcode allows you to display products by post ID, SKU, categories, attributes, with support for pagination, random sorting, and product tags, replacing the need for multiples shortcodes such as [featured_products]
, [sale_products]
, [best_selling_products]
, [recent_products]
, [product_attribute]
, and [top_rated_products]
, which are needed in versions of WooCommerce below 3.2. Review the examples below.
Available Product Attributes
The following attributes are available to use in conjunction with the [products]
shortcode. They have been split into sections for primary function for ease of navigation, with examples below.
Display Product Attributes
limit
– The number of products to display. Defaults to and-1
(display all) when listing products, and-1
(display all) for categories.columns
– The number of columns to display. Defaults to4
.paginate
– Toggles pagination on. Use in conjunction withlimit
. Defaults tofalse
set totrue
to paginate .orderby
– Sorts the products displayed by the entered option. One or more options can be passed by adding both slugs with a space between them. Available options are:date
– The date the product was published.id
– The post ID of the product.menu_order
– The Menu Order, if set (lower numbers display first).popularity
– The number of purchases.rand
– Randomly order the products on page load (may not work with sites that use caching, as it could save a specific order).rating
– The average product rating.title
– The product title. This is the defaultorderby
mode.
skus
– Comma-separated list of product SKUs.category
– Comma-separated list of category slugs.tag
– Comma-separated list of tag slugs.order
– States whether the product order is ascending (ASC
) or descending (DESC
), using the method set inorderby
. Defaults toASC
.class
– Adds an HTML wrapper class so you can modify the specific output with custom CSS.on_sale
– Retrieve on sale products. Not to be used in conjunction withbest_selling
ortop_rated
.best_selling
– Retrieve the best selling products. Not to be used in conjunction withon_sale
ortop_rated
.top_rated
– Retrieve top-rated products. Not to be used in conjunction withon_sale
orbest_selling
.
Content Product Attributes
attribute
– Retrieves products using the specified attribute slug.terms
– Comma-separated list of attribute terms to be used withattribute
.terms_operator
– Operator to compare attribute terms. Available options are:AND
– Will display products from all of the chosen attributes.IN
– Will display products with the chosen attribute. This is the defaultterms_operator
value.NOT IN
– Will display products that are not in the chosen attributes.
tag_operator
– Operator to compare tags. Available options are:AND
– Will display products from all of the chosen tags.IN
– Will display products with the chosen tags. This is the defaulttag_operator
value.NOT IN
– Will display products that are not in the chosen tags.
visibility
– Will display products based on the selected visibility. Available options are:visible
– Products visible on shop and search results. This is the defaultvisibility
option.catalog
– Products visible on the shop only, but not search results.search
– Products visible in search results only, but not on the shop.hidden
– Products that are hidden from both shop and search, accessible only by direct URL.featured
– Products that are marked as Featured Products.
category
– Retrieves products using the specified category slug.tag
– Retrieves products using the specified tag slug.cat_operator
– Operator to compare category terms. Available options are:AND
– Will display products that belong in all of the chosen categories.IN
– Will display products within the chosen category. This is the defaultcat_operator
value.NOT IN
– Will display products that are not in the chosen category.
ids
– Will display products based on a comma-separated list of Post IDs.skus
– Will display products based on a comma-separated list of SKUs.
Products display shortcode:
[products limit="4" columns="4" orderby="popularity" class="quick-sale" on_sale="true"]
[products limit="8" columns="4" category="hoodies, tshirts" cat_operator="AND"]
[products columns="3" attribute="season" terms="warm" orderby="date"]
[products columns="3" attribute="season" terms="warm" terms_operator="NOT IN"]
[products tag="hoodie"]
You can also sort products by custom meat field. To do that, you need to use add_filter
add_filter( 'woocommerce_shortcode_products_query', 'woocommerce_shortcode_products_orderby' );
Read more about that here: Sorting Products by Custom Meta Fields
https://woocommerce.com/document/woocommerce-shortcodes/
https://www.cloudways.com/blog/woocommerce-shortcodes/