# "New" Badge for Recent Products

> Shows a "New" label on products in the shop that were published in the last 30 days.

- Type: PHP
- Runs: Run everywhere
- Category: [WooCommerce](https://wpide.com/library/category/woocommerce/)
- Requires: WooCommerce
- Tags: woocommerce, badge, shop, new
- Author: WPIDE Team
- Installs: 0
- Updated: 2026-10-28
- Page: https://wpide.com/library/woo-new-product-badge/

## Code

```php
add_action( 'woocommerce_before_shop_loop_item_title', function () {
    global $product;

    $days = 30; // Products newer than this many days get the badge.

    if ( ! $product instanceof WC_Product || ! $product->get_date_created() ) {
        return;
    }

    $age = time() - $product->get_date_created()->getTimestamp();

    if ( $age > $days * DAY_IN_SECONDS ) {
        return;
    }

    echo '<span class="wpide-new-badge" style="position:absolute;top:10px;right:10px;z-index:9;padding:4px 10px;border-radius:3px;background:#2271b1;color:#fff;font-size:12px;font-weight:600;text-transform:uppercase;">' . esc_html( 'New' ) . '</span>';
}, 9 );

add_action( 'wp_head', function () {
    echo '<style>.woocommerce ul.products li.product{position:relative;}</style>' . "\n";
} );
```

## Notes

Change $days to control how long a product counts as new.

## How to use it

Install the free WPIDE plugin (https://wordpress.org/plugins/wpide/), find ""New" Badge for Recent Products" in its snippet library and add it in one click; or create a new PHP snippet in WPIDE (or any code snippets plugin) and paste the code above. More snippets: https://wpide.com/library/
