May 22, 2023

Highlight New Products with a WooCommerce New Badge

Play Video

What is the tutorial about?

Web Squadron explains how to add a WooCommerce new badge to your recently added products in your store using a free code snippet. The badge will be visible for a set number of days, indicating to your customers that the product is new. This is an excellent way to highlight new products and attract customer attention.

Use Cases for this Tutorial

  • Online Store Owners:
    If you’re running an online store and frequently add new products, this tutorial will help you highlight those new additions effectively.
  • Web Designers:
    This tutorial can be a handy tool for web designers who want to add dynamic elements to the WooCommerce stores they design.
  • Marketing Professionals:
    For those involved in marketing, this tutorial can help create a sense of urgency and novelty, encouraging customers to check out new products.
  • WordPress Developers:
    Developers can use this tutorial to learn more about using code snippets and plugins in WordPress, expanding their toolkit.

Required Code

Source: Code Snippets

/**
 * Snippet Name:	WooCommerce Show "NEW" Badge On Newly Added Products
 * Snippet Author:	ecommercehints.com
 */

// Show the NEW badge on the archive loop item
add_action( 'woocommerce_after_shop_loop_item_title', 'ecommercehints_product_archive_new_badge', 1 );
function ecommercehints_product_archive_new_badge() {
   global $product;
   $days_to_show = 10; // Show the new badge for 10 days
   $product_published_date = strtotime( $product->get_date_created() );
   if ( ( time() - ( 60 * 60 * 24 * $days_to_show ) ) < $product_published_date ) {
      echo '<span class="onsale">' . 'NEW!' . '</span>'; // The "NEW!" text with the sale badge styling
   }
}

// Show the NEW badge on the single product template
add_action( 'woocommerce_single_product_summary', 'ecommercehints_single_product_new_badge', 3 );  
function ecommercehints_single_product_new_badge() {
   global $product;
   $days_to_show = 10; // Show the new badge for 10 days
   $product_published_date = strtotime( $product->get_date_created() );
   if ( ( time() - ( 60 * 60 * 24 * $days_to_show ) ) < $product_published_date ) {
      echo '<span class="onsale">' . 'NEW!' . '</span>'; // The "NEW!" text with the sale badge styling
   }
}

Required Resources

WooCommerce Logo
Free Options
Code Snippets Logo
Free Options
Credit to Web Squadron
Web Squadron is a popular YouTube channel dedicated to providing informative tutorials, tips, and insights on web development and design. With a strong focus on WordPress and website builders like Bricks Builder, the channel aims to help users of all skill levels, from beginners to advanced developers, create and optimize their websites. By offering easy-to-understand, step-by-step guidance, Web Squadron provides practical and valuable content.
Visit
Highlight New Products with a WooCommerce New Badge
Welcome back!
Enter your Helwp credentials to sign in.

No Account yet? Sign Up

My Account
Menu
Give Feedback
Describe your feedback *
Rate Helwp
Share
Facebook
Twitter
LinkedIn
Reddit
Email
WhatsApp
Telegram
Pocket
Report
Problem *
Describe the problem
Want us to reply?
Your E-Mail
Affiliate Disclosure

At Helwp, we’re committed to transparency and honesty. Therefore, we want to inform you that some of the links on our website are affiliate links. This means that, at no additional cost to you, we may earn a small commission if you click through and make a purchase.

We only promote products or services that we genuinely believe in. These affiliate commissions help us to maintain the website and continue to provide you with free, high-quality WordPress content.

If you are interested in how you can support us even further, check out our support page.