"Was / Now" Sale Price Format
Replaces the crossed-out sale price layout with clear "Now 20.00, was 25.00" wording that reads better and works with screen readers.
Opens WPIDE on
Code
$wpide_was_now = array(
'now' => 'Now',
'was' => 'was',
);
add_filter( 'woocommerce_format_sale_price', function ( $html, $regular, $sale ) use ( $wpide_was_now ) {
$regular = is_numeric( $regular ) ? wc_price( $regular ) : $regular;
$sale = is_numeric( $sale ) ? wc_price( $sale ) : $sale;
return sprintf(
'<span class="wpide-now">%1$s %2$s</span> <span class="wpide-was">%3$s <del>%4$s</del></span>',
esc_html( $wpide_was_now['now'] ),
wp_kses_post( $sale ),
esc_html( $wpide_was_now['was'] ),
wp_kses_post( $regular )
);
}, 10, 3 );
Notes
Change the words in $wpide_was_now to match your tone.
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.