Woocommerce shortcodes are small snippets of code that you can place in your Woocommerce pages and templates to show certain values from the database. You don’t have to be an experienced coder to work with shortcodes which is what makes them so popular! We wanted to compile the biggest and most helpful list of Woocommerce shortcodes in order to have them all in one place… so here ya go.
In order to integrate Woocommerce into your WordPress website in 2017, you must have 4 key pages installed that allow visitors to checkout, pay and manage their account.
Page Shortcodes:
- [woocommerce_cart] – shows the cart page
- [woocommerce_checkout] – shows the checkout page
- [woocommerce_order_tracking] – shows the order tracking form
- [woocommerce_my_account] – shows the user account page
*Old Page Shortcodes:
[woocommerce_edit_account] – Edit account page[woocommerce_edit_address] – Edit address page[woocommerce_change_password] – Change password page[woocommerce_lost_password] – Lost password page[woocommerce_view_order] – View order pages[woocommerce_logout] – Logout[woocommerce_pay] – Checkout Payment Page[woocommerce_thankyou] – Checkout thank you page
*Note that these shortcodes no longer work in Woocommerce 2.1 and higher. If you have upgraded to Woocommerce 2.1, you can delete these pages with no harm to your site.
Usually these 4 pages are installed by default when you activate Woocommerce but sometimes they may not be but that’s OK because Woocommerce comes with a tool that creates the pages for you.
Just go to Woocommerce->System Status and you will see a tools menu at the top.
Click the tools tab and to view the list of tools that Woocommerce comes with.
In the middle, you will see a tool that says “Install Woocommerce Pages” and a button to install them.
Simply click the button and the 4 pages will be created with the Woocommerce shortcodes installed on them already!
Manually Adding Shortcodes to Pages
If you want to manually add shortcodes to WordPress pages, its pretty simple.
FREE SEO Website Audit
Get more traffic online with this Free SEO Website Analysis.
Lets walk through an example to show you how easy it is to create the checkout page.
First, copy the checkout shortcode [woocommerce_checkout] and go to your Pages section in WP Admin.
Click the Add New Page link and create a new page that will be our Checkout page.
Make the title of the page Checkout and then click inside the WYSIWiG editor where we will paste the shortcode.
Paste the copied [woocomerce_checkout] shortcode into the visual editor of the page. (Note: you can paste it in the text version of the editor as well)
Click the publish button to publish the page.
You now have created a Woocommerce checkout page using shortcodes!
Manually Adding Shortcodes to PHP Templates
You can also add shortcodes to PHP Woocommerce (and WordPress) templates to display certain products and categories throughout your website.
This will allow you to completely customize your WordPress website and integrate Woocommerce shortcodes into all areas of your site.
This is possible by using the do_shortcode() function in WordPress.
You can add any shortcode to a template by pasting the shortcode inside this function like so:
echo
do_shortcode(
'[my_shortcode]'
);
Lets do an example, so you can get a better idea of how to add the shortcodes to PHP templates.
Lets add a recent products section to our homepage to display 4 recent products.
First, we need to build our Woocommerce shortcode to display the recent products.
Our shortcode will look something like this (please see below for shortcode reference guide).
[recent_products per_page="4" columns="1" orderby="date" order="desc"]
This will show 4 of the most recent products in 1 column, ordered by the date descending.
Now, we just need to add this Woocommerce shortcode to the php do_shortcode function and add it to our homepage template.
Find where you want to add your recent products and paste the shortcode inside the do_shortcode function.
You can replace the shortcode with any of the shortcodes below and you can implement them in any of the templates!
Woocommerce Shortcodes
Add to Cart
Show an add to cart button and the price for any product ID.
Arguments:
- id – The id of the product for the add to cart button
- style – Extra css to add to the button
- sku – The sku of the product for the add to cart button
Shortcode:
[add_to_cart id="27" style="border-right:1px solid #ccc"]
Add to Cart URL
If you you want to just echo the URL of the add to cart action for a certain product id or SKU, use the add to cart URL shortcode:
Arguments:
- id – The id of the product add to cart URL
- sku – the sku of the product add to cart URL
Shortcode:
[add_to_cart_url id="99"]
Cart
The cart shortcode is used as the cart page where customers can view their cart, remove items, update items and enter coupon codes. As discussed before, its 1 of 4 pages that are required in order to have a working Woocommerce store.
Arguments: none
Shortcode:
[woocommerce_cart]
Checkout
Shows the checkout pages and process to enter billing and pay for an item. This is 1 of 4 pages that are required in order to have a working Woocommerce store.
Arguments: none
Shortcode:
[woocommerce_checkout]
My Account
The my account shortcode is used as the page for customers to manage accounts, track orders, update their information and more. It contains arguments to specify the numbers of orders to show in their account.
Arguments:
- current_user – The id of the current users account
- order_count – The number of orders to show in my account. (Set to -1 to show all orders)
Shortcode:
[woocommerce_my_account order_count="19"]
Order Tracking Form
Shows a order tracking form where a customer can see the status of their orders by entering order details.
Arguments: none
Shortcode:
[woocommerce_order_tracking]
Product Shortcodes
Featured Products
This shortcode will display any product that you select as a featured product in Woocommerce. You can use arguments to display columns and order the results.
Arguments:
- per_page – how many products to show per page.
- columns – The number of columns to put the products in.
- orderby – You can order the results by title, date, etc.
- order – Display the results ordered descending or ascending.
Shortcode:
[featured_products per_page="12" columns="3" orderby="date" order="desc"]
Product
The Product shortcode shoes a single product by either SKU or product ID.
Arguments:
- id – The id of the product to show.
- sku – The sku of the product to show.
[product id="7"]
Products
This shortcode shows a set of products by ids or skus. You can also use the arguments to add columns, orderby, and order filters.
Arguments:
- columns – How many columns to show the products in.
- orderby – What to order the products by.
- order – Ascending or descending order.
[products id="7, 9, 22, 15, 22, 67" orderby="title" order="desc"]
Product Attribute
This shortcode will list products with a certain attribute. The product attribute shortcode could be good for the homepage or list pages.
Arguments:
- per_page – How many products to show per page.
- columns – How many columns to show the products in.
- orderby – What to order the results by.
- order – Order the results in asc or desc order.
- attribute – a product attribute to filter by.
- filter – the specific attribute to show in the filter.
Shortcode:
[product_attribute columns="4" attribute="color" filter="green"]
Product Category
The product category shortcode will show multiple products in a certain category based on the arguments provided.
Arguments:
- per_page – How many products to show per page.
- columns – How many columns to show the products in.
- orderby – What to order the results by.
- order – Order the results in asc or desc order.
- category – The category to filter products by.
Shortcode:
[product_category category="truck-parts"]
Product Categories
Product Categories shortcode will display the product categories that you have created in the Woocommerce product categories section.
Arguments:
- number – Displays the number of products returned.
- orderby – What to order the results by.
- order – Order the results in asc or desc order.
- columns – How many columns to show the categories in.
- hide_empty – Set to 1 to hide categories with no products.
- parent – Set to 0 to only display top level categories
- ids – Show certain categories
Shortcode:
[product_categories ids="22,34,65,24,44" columns="3" hide_empty="1" parent="0"]
Product Page
Shows the full single product detail page by sku or id.
Arguments:
- id – The id of the product to show.
- sku – The sku of the product to show.
Shortcode:
[product_page id="22"]
Recent Products
This shortcode will display the most recent product added to Woocommerce. Use the per_page argument to limit results per page, the columns argument to show in a certain number of columns and the order arguments to order your results.
Arguments:
- per_page – How many products to show per page.
- columns – How many columns to show the products in.
- orderby – What to order the results by.
- order – Order the results in asc or desc order.
Shortcode:
[recent_products per_page="28" columns="4" orderby="title" order="desc"]
Sale Products
List all the products that are currently on sale. To make products on sale, simply add a price to the sale field in the edit product page of Woocommerce and they will be display here.
Arguments:
- per_page – How many products to show per page.
- columns – How many columns to show the products in.
- orderby – What to order the results by.
- order – Order the results in asc or desc order.
Shortcode:
[sale_products per_page="12" orderby="sale_price" order="desc"]
Best-Selling Products
This shortcode will display all the best selling products that are currently on sale.
Arguments:
- per_page – How many products to show per page.
- columns – How many columns to show the products in.
Shortocde:
[best_selling_products per_page="8"]
Related Products
Shortcode to display related products.
Arguments:
- per_page – How many products to show per page.
- columns – How many columns to show the products in.
- orderby – What to order the results by.
Shortcode:
[related_products per_page="4"]
Top Rated Products
List the top rated products by reviews.
Arguments:
- per_page – How many products to show per page.
- columns – How many columns to show the products in.
- orderby – What to order the results by.
- order – Order the results in asc or desc order.
Shortcode:
[top_rated_products per_page="6" columns="2"]
More About Order & Orderby
The orderby argument takes the following values which can each be ordered by asc or desc:
- date – Order by the date.
- id – Order by product id.
- menu_order – List in order of in menu.
- rand – Show in a random order.
- title – Order by the title of the Product.
To sort by custom meta fields, insert the following code into your functions.php page and change the ‘meta_value_num’ string to whatever your custom meta field value is.
add_filter( 'woocommerce_shortcode_products_query', 'woocommerce_shortcode_products_orderby' ); function woocommerce_shortcode_products_orderby( $args ) { $standard_array = array('menu_order','title','date','rand','id'); if( isset( $args['orderby'] ) && !in_array( $args['orderby'], $standard_array ) ) { $args['meta_key'] = $args['orderby']; $args['orderby'] = 'meta_value_num'; } return $args; }
FREE SEO Website Audit
Get more traffic online with this Free SEO Website Analysis.