Troubleshooting shortcodes

On this page, you’ll find a few common reasons why WooCommerce shortcodes may not work as expected.

Shortcodes cannot be embedded between <pre> tags

If your shortcodes are correctly pasted but display incorrectly, ensure they are not enclosed between <pre> tags.

To remove these tags, edit the page, and click the Text tab:

A shortcode wrapped in <pre> tags in an editable text field.

Incorrect quotation marks

↑ Back to top

A common problem is when straight quotation marks (") are used instead of curly quotation marks (). For shortcodes to function correctly, you must use straight quotation marks.

Variation product SKU not shown

↑ Back to top

When using an SKU shortcode (such as [products skus="sku-name"]), do not use the variation name SKU from Product data > Variable product > Variations > Variation name > SKU should not be used.

The solution is to instead use an SKU from the parent variable product‘s Product data meta box — Product data > Variable product > Inventory > SKU.

A variable product's SKU shown in the Inventory tab of a WooCommerce product page.

Code snippets

↑ Back to top

Note: We are unable to provide support for customizations under our Support Policy. If you need to customize a snippet or extend its functionality, please seek assistance from a qualified WordPress/WooCommerce developer. We highly recommend Codeable or a Woo Agency Partner.

Top-level Product Categories List

↑ Back to top

The Product Categories List block displays a list of all product categories, both top-level and sub-categories alike. It cannot display only top-level categories.

The snippet below adds a new shortcode — [top_level_product_categories_list] — which outputs a bulleted list of top-level product categories only. Add it to a child theme’s functions.php file or via a code snippets extension/plugin.

wc-shortcode-top-level-product-category-list.php content:
<?php
/*
 * The shortcode is [top_level_product_categories_list] 
 */
add_shortcode('top_level_product_categories_list', 'wc_shortcode_top_level_product_categories_list');

function wc_shortcode_top_level_product_categories_list() {
    
   ob_start();
   
   $args = array(
        'taxonomy' => 'product_cat',
        'parent' => 0
    );
    
    $product_categories = get_categories($args);
	
    echo '<ul>';
    
    foreach ($product_categories as $category) {
        echo '<li><a href="' . get_term_link($category->slug, 'product_cat') . '">' . $category->name . '</a></li>';
    }
	
    echo '</ul>';
    
    return ob_get_clean();
}

View on Github

Questions and support

↑ Back to top

Do you still have questions and need assistance? 

This documentation is about the free, core WooCommerce plugin, for which support is provided in our community forums on WordPress.org. By searching this forum, you’ll often find that your question has been asked and answered before.

If you haven’t created a WordPress.org account to use the forums, here’s how.

  • If you’re looking to extend the core functionality shown here, we recommend reviewing available extensions in the WooCommerce Marketplace.
  • Need ongoing advanced support or a customization built for WooCommerce? Hire a Woo Agency Partner.
  • Are you a developer building your own WooCommerce integration or extension? Check our Developer Resources.

If you weren’t able to find the information you need, please use the feedback thumbs below to let us know.

Use of your personal data
We and our partners process your personal data (such as browsing data, IP Addresses, cookie information, and other unique identifiers) based on your consent and/or our legitimate interest to optimize our website, marketing activities, and your user experience.