Skip to content

Instantly share code, notes, and snippets.

Show Gist options
  • Save sarancartrabbit/5f72df0900b0753fed7b8b99915d9477 to your computer and use it in GitHub Desktop.
Save sarancartrabbit/5f72df0900b0753fed7b8b99915d9477 to your computer and use it in GitHub Desktop.
Discount rules v2: To show the default variant price for strikeout
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') && function_exists('wc_price')) {
$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) {
$html = '<del>' . wc_price($sale_price) . '</del>&nbsp;<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