Shortcodes included with WooCommerce

Shortcodes included with WooCommerce

ABOUT

The Coupon Shortcodes extension allows you to render coupon information and show content based on the validity of coupons.

Customers can be motivated to proceed with their purchase, offering them to use specific coupons when the contents in the cart qualify for it, or by offering them to purchase additional items so they can use a coupon.

Conditional Shortcodes

It provides the following conditional shortcodes that allow enclosing content which is shown if coupons are applied, valid or not valid.

Coupon Info Shortcodes

It also provides shortcodes that allow to render the coupon code, its description and an automatic description of the discount:

A coupon enumerator shortcode allows to list all or a set of coupons, to show their code, description or discount information.

Documentation

Please refer to the plugin’s documentation for detailed descriptions.

Examples

Show a text when a coupon can be used (active) – this is useful to show promotional info while coupons can be used, as active means that the coupon has not reached its expiration date nor exceeded its usage limits:

Happy Easter!
Use the coupon code to hop away with a great discount.

This is an example of a text shown when a promotion is over:

Our special discount sale has ended. Come back often to see more!

Showing a coupon when the cart contents qualify for a coupon to be applied:

You qualify for a discount!
Use the coupon code to take advantage of this great discount.

Showing a coupon that is not valid for the current cart and motivating to add items:

If you purchase 5 Widgets, you can use the coupon to get 25% off your purchase!

Show information about three random coupons, including the coupon code, its description and discount info together on each entry.

Show a single random coupon code.

SETUP

WooCommerce comes with several shortcodes that can be used to insert content inside posts and pages.

Our WooCommerce blocks are now the easiest and most flexible way to display your products on posts and pages on your WooCommerce site. Read more about all the available WooCommerce blocks here.

How to use shortcodes

Where to use

Shortcodes can be used on pages and posts in WordPress. If you are using the block editor, there is a shortcode block you can use to paste the shortcode in.

If you are using the classic editor, you can paste the shortcode on the page or post.

Args (or Arguments)

Several of the shortcodes below will mention “Args”. These are ways to make the shortcode more specific. For example, by adding id="99" to the shortcode, it will create an add-to-cart button for the product with ID 99.

Page Shortcodes

WooCommerce cannot function properly without the first three shortcodes being somewhere on your site.

Note: You can now test the new cart and checkout blocks that are available in the WooCommerce Blocks plugin!

These shortcodes will be added to pages automatically via our onboarding wizard and do not need to be used manually.

Cart

Used on the cart page, the cart shortcode displays cart content and interface for coupon codes and other cart bits and pieces.
Args: none

Checkout

Used on the checkout page, the checkout shortcode displays the checkout process.
Args: none

My Account

Shows the ‘my account’ section where the customer can view past orders and update their information. You can specify the number of orders to show. By default, it’s set to 15 (use -1 to display all orders.)
Args:

Current user argument is automatically set using get_user_by( 'id', get_current_user_id() ).

Order Tracking Form

Lets a user see the status of an order by entering their order details.
Args: none

Products

Notes
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.

It allows you to display products by post ID, SKU, categories, attributes, with support for pagination, random sorting, and product tags, replacing the need for multiple shortcodes used in older versions of WooCommerce.

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.

Display Product Attributes:

  1. limit – The number of products to display. Defaults to -1 (display all).

  2. columns – The number of columns to display. Defaults to 4.

  3. paginate – Toggles pagination on. Use in conjunction with limit. Defaults to false.

  4. orderby – Sorts the products displayed. Options include:

    • date – The date the product was published.

    • id – The post ID of the product.

    • menu_order – The menu order, if set.

    • popularity – The number of purchases.

    • rand – Randomly order products on page load.

    • rating – The average product rating.

    • title – The product title (default).

  5. skus – Comma-separated list of product SKUs.

  6. category – Comma-separated list of category slugs.

  7. tag – Comma-separated list of tag slugs.

  8. order – ASC or DESC.

  9. class – Adds a CSS class for styling.

  10. on_sale – Show products on sale.

  11. best_selling – Show best-selling products.

  12. top_rated – Show top-rated products.

Content Product Attributes:

  1. attribute – Retrieves products using a specific attribute slug.

  2. terms – List of attribute terms.

  3. terms_operator – Operators: AND, IN (default), NOT IN.

  4. tag_operator – Operators: AND, IN (default), NOT IN.

  5. visibility – Options:

    • visible – On shop and search (default).

    • catalog – Shop only.

    • search – Search only.

    • hidden – Hidden from shop/search.

    • featured – Marked as Featured Products.

  6. category – Retrieves products using a category slug.

  7. tag – Retrieves products using a tag slug.

  8. cat_operator – Category term operator: AND, IN (default), NOT IN.

    • Related Articles

    • Woocommerce Refunds

      Summary In WooCommerce itself you can process refunds in two ways: Automatic: Refunds change the WooCommerce order status and also reverse the charge so your customer gets their money. Manual: Refunds change the WooCommerce order status, but you need ...
    • WooCommerce Analytics

      Orders are created when a customer completes the checkout process, and they are visible only to users with Admin and Shop Manager roles. Each order is given a unique Order ID. Orders can have different statuses depending on their position in the ...
    • WooCommerce Menu Items

      Home Section The Home section is your WooCommerce dashboard. Here you can stay on top of your store performance, get useful tips and insights to grow your business, and quickly access some of the most important areas to manage your store. More ...
    • Woocommerce Home Screen

      Home Screen In WooCommerce Home you can stay on top of your store performance, get useful tips and insights to grow your business, and quickly access some of the most important areas to manage your store. Display Settings In the Activity Panel area ...
    • Configuring WooCommerce Settings

      On this page, we walk through all settings available to you in WooCommerce (some add-ons will embed their own settings in this area). You’ll find information about configuring General WooCommerce settings as well as Product, Tax, Payments, Shipping, ...