Skip to content

Instantly share code, notes, and snippets.

Show Gist options
  • Save AshlinRejo/c3331e061e48e2fa09e08f3654d15fb4 to your computer and use it in GitHub Desktop.
Save AshlinRejo/c3331e061e48e2fa09e08f3654d15fb4 to your computer and use it in GitHub Desktop.
Woo Discount Rules v2 - Fix same price strikeout
function woocommerce_get_price_html_woo_discount_on_sale_compatible($item_price, $product){
$del_pattern = '/<del aria-hidden="true">(.*?)<\/del>/s';
preg_match($del_pattern, $item_price, $matches);
$del_content = isset($matches[1]) ? $matches[1] : '';
$del_content = trim(strip_tags($del_content));
$ins_pattern = "/<ins>(.*?)<\/ins>/s";
preg_match($ins_pattern, $item_price, $matches);
$ins_content = isset($matches[1]) ? $matches[1] : '';
$ins_content = trim(strip_tags($ins_content));
if(!empty($del_content) && !empty($ins_content)){
if($del_content == $ins_content){
$original_price_suffix = '';
if (class_exists('\Wdr\App\Helpers\Woocommerce')) {
$original_price_suffix = \Wdr\App\Helpers\Woocommerce::getProductPriceSuffix($product, $ins_content);
}
$item_price = '<span class="cart_price wdr_product_strikeout">';
$item_price .= $ins_content.$original_price_suffix;
$item_price .= '</span>';
}
}
return $item_price;
}
add_filter('woocommerce_get_price_html', 'woocommerce_get_price_html_woo_discount_on_sale_compatible', 1000, 2);
add_filter('woocommerce_variable_price_html', 'woocommerce_get_price_html_woo_discount_on_sale_compatible', 1000, 2);
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment