Skip to content

Instantly share code, notes, and snippets.

@yayMark
Created October 18, 2018 02:54
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 1 You must be signed in to fork a gist
  • Save yayMark/3d6239674307ec683aeb71c815c04b06 to your computer and use it in GitHub Desktop.
Save yayMark/3d6239674307ec683aeb71c815c04b06 to your computer and use it in GitHub Desktop.
WooCommerce: swap sale and regular pricing display
<?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