Title: Display NEW badge function
Last modified: September 17, 2021

---

# Display NEW badge function

 *  Resolved [databell96](https://wordpress.org/support/users/databell96/)
 * (@databell96)
 * [4 years, 10 months ago](https://wordpress.org/support/topic/display-new-badge-function/)
 * [Found a script to display NEW badges on my most recent products](https://wpsimplehacks.com/how-to-display-new-badge-on-woocommerce-recent-products/)
   and it works on my Shop page, which isn’t using WooCommerce Blocks, but rather
   the standard Woo archive loop. Problem is the scripts don’t seem to add the new
   span to my Woo block.
 * This is the code I’m using:
 *     ```
       // New badge for recent products
       add_action( 'woocommerce_before_shop_loop_item_title', 'new_badge', 3 );
   
       function new_badge() {
          global $product;
          $newness_days = 365; // Number of days the badge is shown
          $created = strtotime( $product->get_date_created() );
          if ( ( time() - ( 60 * 60 * 24 * $newness_days ) ) < $created ) {
             echo '<span class="new-badge onsale">' . esc_html__( 'NEW', 'woocommerce' ) . '</span>';
          }
       }
       ```
   
 * Is there some reason it doesn’t seem to work within a block?
 * The page I need help with: _[[log in](https://login.wordpress.org/?redirect_to=https%3A%2F%2Fwordpress.org%2Fsupport%2Ftopic%2Fdisplay-new-badge-function%2F%3Foutput_format%3Dmd&locale=en_US)
   to see the link]_

Viewing 2 replies - 1 through 2 (of 2 total)

 *  [Austin M – a11n](https://wordpress.org/support/users/apmwebdev/)
 * (@apmwebdev)
 * [4 years, 10 months ago](https://wordpress.org/support/topic/display-new-badge-function/#post-14885737)
 * Hi [@databell96](https://wordpress.org/support/users/databell96/). Blocks are
   set up a bit differently, so it’s not surprising that this code wouldn’t work
   there. You would likely need a snippet that is specific to blocks. Per our [support policy](https://woocommerce.com/support-policy/#customisation),
   customizations are outside the scope of the support we can offer, but we have
   a [customizations page](https://woocommerce.com/customizations/) with resources
   for contacting a developer for help. You can also ask about this on the [WooCommerce Slack Community](https://woocommerce.com/community-slack/)
   or [WooCommerce FB group](https://www.facebook.com/groups/advanced.woocommerce/)
   which are great places for customization questions like this.
 *  Plugin Support [Stuart Duff – a11n](https://wordpress.org/support/users/stuartduff/)
 * (@stuartduff)
 * Automattic Happiness Engineer
 * [4 years, 10 months ago](https://wordpress.org/support/topic/display-new-badge-function/#post-14905614)
 * Hey @databell96
 * We haven’t heard back from you in a while, so I’m going to mark this as resolved–
   if you have any further questions, you can reopen it again if you need be.

Viewing 2 replies - 1 through 2 (of 2 total)

The topic ‘Display NEW badge function’ is closed to new replies.

 * ![](https://s.w.org/plugins/geopattern-icon/woo-gutenberg-products-block_71608f.
   svg)
 * [WooCommerce Blocks](https://wordpress.org/plugins/woo-gutenberg-products-block/)
 * [Support Threads](https://wordpress.org/support/plugin/woo-gutenberg-products-block/)
 * [Active Topics](https://wordpress.org/support/plugin/woo-gutenberg-products-block/active/)
 * [Unresolved Topics](https://wordpress.org/support/plugin/woo-gutenberg-products-block/unresolved/)
 * [Reviews](https://wordpress.org/support/plugin/woo-gutenberg-products-block/reviews/)

## Tags

 * [php](https://wordpress.org/support/topic-tag/php/)

 * 2 replies
 * 3 participants
 * Last reply from: [Stuart Duff – a11n](https://wordpress.org/support/users/stuartduff/)
 * Last activity: [4 years, 10 months ago](https://wordpress.org/support/topic/display-new-badge-function/#post-14905614)
 * Status: resolved