in

Add a Custom WooCommerce Product Badge Based on Stock Status with This Simple Snippet

Help shoppers spot availability at a glance with a WooCommerce custom product badge based on stock status. This simple snippet lets you show different labels for in-stock, out-of-stock, and backorder products, then style them to match your store. Add it, test a few product types, and keep stock information clear.

Want to make product availability easier to spot in your WooCommerce store? A custom badge can highlight whether an item is in stock, on backorder, or unavailable, helping shoppers find the information they need at a glance.

In this guide, you’ll learn how to add a WooCommerce custom product badge based on stock status using a simple snippet. It’s a straightforward way to give your product pages a more helpful, personalized touch without adding another plugin.

Why Add a WooCommerce Custom Product Badge Based on Stock Status?

A small label can answer a shopper’s practical question before they open a product page: “Can I get this now?” Once your snippet is in place, thoughtful badge choices can make availability clearer and help set expectations across your catalog.

How stock status can help shoppers make decisions

Availability influences what customers do next. Someone shopping for a last-minute gift may choose an item marked “In stock,” while a customer willing to wait could still consider a product that’s available on backorder. Clear signals help people compare options without having to hunt through product details.

A badge also gives useful context at a glance in shop and category views, where shoppers are often scanning several products at once. For example, “Ships in 2–3 weeks” communicates more than a vague “Backorder” label, provided that estimate is accurate and kept up to date.

  • In stock: Reassures shoppers that the product is currently available.
  • Backorder: Sets expectations that fulfillment may take longer.
  • Sold out: Helps customers avoid choosing an item they can’t currently purchase.

These labels aren’t a substitute for accurate inventory settings, but they can make those settings easier to notice. That’s especially helpful for stores with large catalogs or products whose availability changes often.

Once you know what shoppers need to understand, the next step is choosing language and visual styling that suits your brand. A badge should be easy to recognize without competing with the product image, price, or purchase button.

Choose badge labels and styles that fit your store

Keep wording short and specific. “Available now” might feel warmer than “In stock,” while “Backorder—ships soon” can be useful if you can reliably meet that promise. Avoid implying a delivery date or guaranteed availability unless your store can support it.

Make each status distinct through a combination of color, contrast, and text, rather than color alone. For instance, use a calm green for available products and a contrasting amber for backorders, while ensuring both labels remain readable against your theme’s background.

Before settling on a design, check it on desktop and mobile, and consider how it appears alongside sale labels or other product notices. The best WooCommerce custom product badge based on stock status feels like a natural part of your store: noticeable enough to guide a decision, but simple enough not to distract.

Add a WooCommerce Custom Product Badge Based on Stock Status with This Snippet

Now that you’ve chosen labels that suit your store, you can connect them to WooCommerce’s existing inventory statuses. The snippet below adds a badge to product listings and individual product pages, while keeping the wording and styling easy to adjust.

First, choose a place for the code that’s easy to maintain. A snippets plugin or your child theme is preferable to editing a parent theme, since theme updates can overwrite changes.

Add the PHP snippet to your site

This function checks the product’s stock status, selects the matching label, and outputs a badge. In a snippets plugin, add the code as a PHP snippet; in a child theme’s functions.php, paste it without adding a second PHP opening tag.

addaction( 'woocommercebeforeshoploopitemtitle', 'myshopstockstatusbadge', 10 );
addaction( 'woocommercebeforesingleproductsummary', 'myshopstockstatusbadge', 10 );
function myshopstockstatusbadge() {
    global $product;
    if ( ! $product instanceof WCProduct ) {
        return;
    }
    $status = $product->getstockstatus();
    $labels = array(
        'instock'     => 'Available now',
        'onbackorder' => 'Backorder',
        'outofstock'  => 'Sold out',
    );
    if ( ! isset( $labels[ $status ] ) ) {
        return;
    }
    echo '<span class="custom-stock-badge custom-stock-badge--'
        . escattr( $status ) . '">'
        . esc_html( $labels[ $status ] ) . '</span>';
}

The function uses escaped output and a distinctive name to reduce the chance of conflicts. If your theme places the badge awkwardly, you can change the hook or its priority; test the result with your theme and any product-display plugins.

With the output in place, each WooCommerce stock status can have its own concise message. The array is the only part you need to edit to change the labels.

Set badge text for in-stock, out-of-stock, and backorder products

In the $labels array, replace the sample text with wording that matches your fulfillment process. For example, you might use “Ready to ship” for in-stock items or “Ships when available” for backorders—but only make delivery promises you can reliably meet.

  • instock applies to products available for purchase.
  • onbackorder identifies products customers can order before they’re replenished.
  • outofstock marks products that aren’t currently available.

WooCommerce reads these statuses from product inventory settings, so check that those settings are accurate. If you sell variable products, test the parent listing and individual variations to confirm the badge behavior suits your setup.

Finally, a little CSS can make the label feel at home in your design. These styles provide a simple starting point without relying on color alone to communicate the status.

Customize the badge’s appearance with CSS

Add the rules in Appearance → Customize → Additional CSS or your theme’s equivalent. Adjust the colors, spacing, and shape to complement your existing product cards.

.custom-stock-badge {
  display: inline-block;
  padding: 5px 9px;
  border-radius: 4px;
  font-size: 0.85rem;
  font-weight: 700;
  line-height: 1.3;
  color: #fff;
  background: #287a3e;
}
.custom-stock-badge--onbackorder {
  color: #222;
  background: #ffd36a;
}
.custom-stock-badge--outofstock {
  background: #666;
}

Preview the result on mobile and desktop, including alongside sale labels. Clear text and sufficient contrast help every shopper understand the message at a glance.

Test and Troubleshoot Your Stock-Based Badge

A badge that looks right in the editor can behave differently across product pages, categories, and devices. A quick round of checks now can catch confusing labels or layout surprises before shoppers encounter them.

Start by comparing the badge with the way your catalog is actually configured. The checks below cover common product types and stock states, so you can confirm the message shoppers see matches what they can buy.

Check the badge on different product types and stock states

Test at least one simple product in each relevant state: in stock, on backorder, and out of stock. Check both its individual page and a shop or category listing, and confirm the text and styling appear only once in each location.

Variable products need extra attention. Depending on how stock is managed, the parent product’s status may not reflect the availability of every variation. Check the parent listing and the variation-selection experience, especially when some options are available and others are sold out. The WooCommerce variable product documentation explains how variation settings affect product behavior.

Also test a product with backorders disabled and one with backorders enabled. If out-of-stock products are hidden from your catalog, you may not see their badges in listings; visit the product directly to check whether the single-product badge is useful in your setup.

If a test fails, the cause is often a theme template, a conflicting display feature, or a small styling issue rather than the status labels themselves. These quick checks can help narrow it down without changing several parts of the snippet at once.

Fix common display and compatibility issues

If no badge appears, confirm the snippet is active, saved as PHP, and free of syntax errors. Some themes replace or rearrange WooCommerce’s default template hooks, so the badge may need a different hook or priority. Test changes on a staging site when possible.

When the badge appears twice, check for another snippet, plugin, or theme feature that outputs stock notices. If it overlaps a sale label or product image, adjust the CSS positioning or spacing to suit your theme. A badge that looks correct on desktop may still wrap or cover important details on a narrow screen.

Store updates can change templates, inventory settings, and the way products are presented. A small maintenance routine helps keep your WooCommerce custom product badge based on stock status accurate as the catalog evolves.

Keep the snippet working as your store changes

After updating WooCommerce, your theme, or a product-display plugin, recheck one product page and one listing page. Keep a copy of the working snippet and note any customized hooks or labels so you can restore them if a future change affects the display.

Review stock settings whenever your fulfillment process changes, too. In particular, make sure backorder wording remains accurate and that staff know which inventory status triggers each label. Test after changes to product types, theme templates, or stock rules to ensure the badge still communicates the right information.

Make Product Availability Clearer with a Stock-Based Badge

A WooCommerce custom product badge based on stock status gives shoppers a quick, clear view of availability across your store. With a lightweight snippet, you can tailor the labels and styling to your brand while helping customers understand whether an item is ready to ship, on backorder, or unavailable.

Keep your stock settings accurate, choose wording that reflects what your store can deliver, and test the badge across product types, pages, and screen sizes. A little follow-up after site updates can keep it looking right and communicating the right message. It’s a simple improvement that makes product browsing more helpful and sets clearer expectations from the start.

Leave a Reply

Your email address will not be published. Required fields are marked *

      Written by Maeve Rodriguez

      Maeve is a Business Content Writer and Front-End Developer. She's a versatile professional with a talent for captivating writing and eye-catching design.