Skip to content

Instantly share code, notes, and snippets.

@kimcoleman
Last active June 8, 2022 16:51
Show Gist options
  • Save kimcoleman/64daef80d23f89468531e31ffa3375ef to your computer and use it in GitHub Desktop.
Save kimcoleman/64daef80d23f89468531e31ffa3375ef to your computer and use it in GitHub Desktop.
Format WooCommerce Sale Prices for Accessibility.
<?php
/**
* Format WooCommerce Sale Prices for Accessibility.
*/
function modify_woocommerce_format_sale_price( $price, $regular_price, $sale_price ) {
$price = '<span class="sr-only">Original price</span> <s>' . ( is_numeric( $regular_price ) ? wc_price( $regular_price ) : $regular_price ) . '</s> <span class="sr-only">sale price</span> <ins>' . ( is_numeric( $sale_price ) ? wc_price( $sale_price ) : $sale_price ) . '</ins>';
return $price;
}
add_filter( 'woocommerce_format_sale_price', 'modify_woocommerce_format_sale_price', 10, 3 );
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment