Use the badge_new() function for custom elements

Hi guys,

I would like to add a “New” badge to a custom product card and make use of the existing badge_new() function you provided with the WooCommerce Settings tab. I have just written the function myself but wanted to ask if I can hook into the existing function to avoid duplication?

From the file woocommerce.php, I can see that you’re returning the badge as a <span> element directly. Now I would like to use this function to conditionally show/hide my custom badge but at the moment I only get an Error: Call to undefined method WooCommerce::badge_new() or Error: Call to undefined function badge_new() message when trying to call that function from a code block inside a loop.

Any idea on how to archive that?

1 Like