• Resolved databell96

    (@databell96)


    Found a script to display NEW badges on my most 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 to see the link]

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

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