Skip to content

Instantly share code, notes, and snippets.

@Bradley-D
Last active November 27, 2017 03:52
Show Gist options
  • Star 2 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save Bradley-D/1c092a62b9b6475dca49 to your computer and use it in GitHub Desktop.
Save Bradley-D/1c092a62b9b6475dca49 to your computer and use it in GitHub Desktop.
// Add text before sale price only
function bd_sale_price_html( $price, $product ) {
if ( $product->is_on_sale() ) :
$return_string = str_replace( '<ins>, '<ins><br>Sale Price: ', $price);
return $return_string;
else :
return $price;
endif;
}
add_filter( 'woocommerce_get_price_html', 'bd_sale_price_html', 100, 2 );
// Add text before regular price and sale price
function bd_rrp_sale_price_html( $price, $product ) {
if ( $product->is_on_sale() ) :
$has_sale_text = array(
'<del>' => '<del>RRP: ',
'<ins>' => '<br>Sale Price: <ins>'
);
$return_string = str_replace(array_keys( $has_sale_text ), array_values( $has_sale_text ), $price);
else :
$retun_string = 'RRP: ' . $price;
endif;
return $return_string;
}
add_filter( 'woocommerce_get_price_html', 'bd_rrp_sale_price_html', 100, 2 );
// Add text before regualr price only
function bd_rrp_price_html( $price, $product ) {
$retun_string = 'RRP: ' . $price;
return $return_string;
}
add_filter( 'woocommerce_get_price_html', 'bd_rrp_price_html', 100, 2 );
@crossreftech
Copy link

Under the RRP in front of regular price $retun_string should be $return_string. Works great, thanks.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment