WooCommerce allows you to “schedule” the product sale price – you can define a start date and an end date, so that you can run your promotion automatically.
However, for some reason, this information is only visible to the admin. It would be awesome to show the “sale price end date” to customers as well, don’t you think? So, let’s do it!
PHP Snippet: Add Sale Price End Date to Sale Badge @ WooCommerce Shop, Archive, Product Pages
/**
* @snippet Sale Price End Date @ WooCommerce Archive & Single Product
* @how-to businessbloomer.com/woocommerce-customization
* @author Rodolfo Melogli, Business Bloomer
* @compatible WooCommerce 7
* @community https://businessbloomer.com/club/
*/
add_filter( 'woocommerce_sale_flash', 'bbloomer_sale_end_date', 9999, 3 );
function bbloomer_sale_end_date( $html, $post, $product ) {
if ( $product->get_date_on_sale_to() ) return $html . ' (ends ' . gmdate( 'd M', $product->get_date_on_sale_to()->getTimestamp() ) . ')';
return $html;
}
Is there a way to add it above the add to cart button?
For sure, just check the visual hook guide for the Shop page and pick the right hook
Can this be displayed only on the single product page? The text is being cut off on the product archive page and partially hidden under the SALE badge.
Sure!