Created
October 18, 2018 02:54
-
-
Save yayMark/3d6239674307ec683aeb71c815c04b06 to your computer and use it in GitHub Desktop.
WooCommerce: swap sale and regular pricing display
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
<?php | |
add_filter( 'woocommerce_get_price_html', 'my_price_html', 100, 2 ); | |
function my_price_html( $price, $product ){ | |
// swap the regular and sale prices | |
$pos_start = strpos($price, '<del>'); | |
if ($pos_start !== false) { | |
$end = '</del>'; | |
$end_length = strlen($end); | |
$pos_end_start = strpos($price, $end); | |
$pos_end = $pos_end_start + $end_length; | |
$regular_price = substr($price, $pos_start, $pos_end); | |
$price_length = strlen($price); | |
$sale_price = substr($price, $pos_end + 1, $price_length); | |
return $sale_price . $regular_price; | |
} | |
return $price; | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment