Skip to content

Instantly share code, notes, and snippets.

@BFTrick
Last active November 15, 2024 15:52
Show Gist options
  • Save BFTrick/47b0710a6d27332d0c109cfe75c58be6 to your computer and use it in GitHub Desktop.
Save BFTrick/47b0710a6d27332d0c109cfe75c58be6 to your computer and use it in GitHub Desktop.
Make WooCommerce Sale Prices Accessible
<?php
/*
Plugin Name: WooCommerce Make Sale Prices Accessible
Plugin URI: https://gist.github.com/BFTrick/47b0710a6d27332d0c109cfe75c58be6
Description: Make WooCommerce sale prices accessible
Version: 1.0
Author: Patrick Rauland
Author URI: http://speakinginbytes.com
License: GPL2
License URI: https://www.gnu.org/licenses/gpl-2.0.html
Text Domain: woocommerce-accessible-sale-price
Domain Path: /languages
*/
if ( ! function_exists( 'patricks_format_accessible_sale_price' ) ) {
/**
* WooCommerce sale prices are not accessible by default.
* Until issue 31099 (https://github.com/woocommerce/woocommerce/issues/31099)
* Or PR 44413 (https://github.com/woocommerce/woocommerce/pull/44413) are resolved
* We need to make our own sale prices accessible
*
*/
function patricks_format_accessible_sale_price( $formatted_price, $regular_price, $sale_price ) {
$formatted_price = '<del>
<span class="screen-reader-text">' . esc_html__('Original price was:', 'woocommerce-accessible-sale-price') . '</span> '
. ( is_numeric( $regular_price ) ? wc_price( $regular_price ) : $regular_price ) .
'</del>
<ins>
<span class="screen-reader-text">' . esc_html__('Current price is:', 'woocommerce-accessible-sale-price') . '</span> '
. ( is_numeric( $sale_price ) ? wc_price( $sale_price ) : $sale_price ) .
'</ins>';
return $formatted_price;
} // end function
}// End if().
add_filter( 'woocommerce_format_sale_price', 'patricks_format_accessible_sale_price', 20, 3 );
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment