Last active
January 19, 2023 05:52
-
-
Save sarancartrabbit/05e29428b8fed0efecefe8b419b082e4 to your computer and use it in GitHub Desktop.
Discount rules v2: To show the default variant price for 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
add_filter('advanced_woo_discount_rules_strikeout_price_html', function ($html, $original_price, $discounted_price, $is_variable_product, $initial_price_html, $separator) { | |
global $product; | |
if ($is_variable_product && !empty($product) && is_object($product)) { | |
foreach ($product->get_available_variations() as $variation) { | |
$default_attributes = true; | |
foreach ($product->get_default_attributes() as $default_key => $default_value) { | |
if ($variation['attributes']['attribute_' . $default_key] != $default_value) { | |
$default_attributes = false; | |
break; | |
} | |
} | |
if ($default_attributes && function_exists('wc_get_product')) { | |
$variation_product = wc_get_product($variation['variation_id']); | |
$sale_price = $variation['display_price']; | |
$discount_price = apply_filters('advanced_woo_discount_rules_get_product_discount_price_from_custom_price', $sale_price, $variation_product, 1, 0, 'discounted_price', true, false); | |
if ($discount_price !== false && wc_price('wc_get_product')) { | |
$html = '<del>' . wc_price($sale_price) . '</del> <ins>' . wc_price($discount_price) . '</ins>'; | |
} | |
break; | |
} | |
} | |
} | |
return $html; | |
},10,6); |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment