Show When a Sale Ends
Displays "Sale ends on 31 May" under the price of products with a scheduled sale end date.
Opens WPIDE on
Code
add_action( 'woocommerce_single_product_summary', function () {
global $product;
if ( ! $product instanceof WC_Product || ! $product->is_on_sale() ) {
return;
}
$end = $product->get_date_on_sale_to();
if ( ! $end ) {
return;
}
echo '<p class="wpide-sale-ends" style="color:#b32d2e;font-weight:600;">' . esc_html( sprintf( 'Sale ends on %s', wc_format_datetime( $end, get_option( 'date_format' ) ) ) ) . '</p>';
}, 11 );
Notes
Only appears when the sale has an end date set in the product's price schedule.
How to add this snippet
- Install WPIDE on your WordPress site (it is free) and open Code Snippets.
- Use snippet above adds it from the library in one click. Or copy the code into a new snippet with the same code type.
- It is added inactive: review the code and settings, then switch it on.