Skip to content

Instantly share code, notes, and snippets.

@Spirecool
Last active April 19, 2021 11:20
Show Gist options
  • Save Spirecool/7f965db3772ec899d2a6d8aadab9287b to your computer and use it in GitHub Desktop.
Save Spirecool/7f965db3772ec899d2a6d8aadab9287b to your computer and use it in GitHub Desktop.
<?php
add_action( 'woocommerce_before_shop_loop_item_title', 'popcorn_new_badge_shop_page', 3 ); // on commence par la position où va se trouver le badge, puis on créé une fonction
function popcorn_new_badge_shop_page() {
global $product;
$newness_days = 30; //ici on met le nombre jours, nouveautés sur les 30 derniers jours dans ce cas présent
$created = strtotime( $product->get_date_created() );
if ( ( time() - ( 60 * 60 * 24 * $newness_days ) ) < $created ) {
echo '<span class="itsnew onsale">' . esc_html__( 'Nouveauté!', 'woocommerce' ) . '</span>';
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment