Last active
October 11, 2021 05:24
-
-
Save Balakrishnan-flycart/af658e02f41a2c0f41a90d99b568ee68 to your computer and use it in GitHub Desktop.
Woo Discount Rules v2 - Fix same price strikeout
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
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