# Show When a Sale Ends

> Displays "Sale ends on 31 May" under the price of products with a scheduled sale end date.

- Type: PHP
- Runs: Run everywhere
- Category: [WooCommerce](https://wpide.com/library/category/woocommerce/)
- Requires: WooCommerce
- Tags: woocommerce, sale, urgency, product-page
- Author: WPIDE Team
- Installs: 0
- Updated: 2026-10-28
- Page: https://wpide.com/library/woo-sale-end-date/

## Code

```php
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 use it

Install the free WPIDE plugin (https://wordpress.org/plugins/wpide/), find "Show When a Sale Ends" in its snippet library and add it in one click; or create a new PHP snippet in WPIDE (or any code snippets plugin) and paste the code above. More snippets: https://wpide.com/library/
