Created
July 13, 2021 15:52
-
-
Save rajucs/e299915401c3a11a70df08682405cd10 to your computer and use it in GitHub Desktop.
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('woocommerce_get_price_html', 'custom_price_html', 100, 2); | |
function custom_price_html($price, $product) | |
{ | |
// if (is_singular('product')) { | |
// return $price; | |
// } else { | |
if ($product->is_type('simple')) { | |
if ($product->is_on_sale()) { | |
$price = | |
' | |
<ins class="en-ins" style="display:block;font-size: 22px !important;"> | |
<span class="woocommerce-Price-amount amount" style="font-size: 22px !important;'.(is_singular('product') ? 'color: #c8791c !important;': 'color: #828282 !important;').'"> | |
<bdi class="woocommerce-Price-currencySymbol" style="font-size: 22px !important;'.(is_singular('product') ? 'color: #c8791c !important;': 'color: #828282 !important;').'">' . get_woocommerce_currency_symbol(). number_format($product->get_sale_price()) . ' | |
</bdi> | |
</span> | |
</ins> | |
'; | |
$price .= ' | |
<span class="en-del" style="font-size: 18px !important;color: #828282 !important;"> | |
Was | |
<del aria-hidden="true" style="font-size: 18px !important;"> | |
<span class="woocommerce-Price-amount amount" style="font-size: 18px !important;color: #828282!important;" > | |
<bdi style="font-size: 18px !important; color: #828282 !important;">' . get_woocommerce_currency_symbol() . number_format($product->get_regular_price()) . ' | |
</bdi> | |
</span> | |
</del> | |
</span> | |
'; | |
} | |
return $price; | |
} else if ($product->is_type('variable')) { | |
$attributes = $product->get_attributes(); | |
if(count($attributes) == 1 ){ | |
if($attributes['pa_color']['name'] == 'pa_color'){ | |
$from = ''; | |
} | |
}else{ | |
if(in_array('pa_color', $attributes)){ | |
echo '33333'; | |
} | |
$from = 'From'; | |
} | |
if ($product->is_on_sale()) { | |
$price = ' | |
<ins class="en-ins" style="display:block;font-size: 22px !important;"> | |
<span class="woocommerce-Price-amount amount" style="font-size: 22px !important;'.(is_singular('product') ? 'color: #c8791c !important;': 'color: #828282 !important;').'"> | |
'.$from.' | |
<bdi style="font-size: 22px !important;'.(is_singular('product') ? 'color: #c8791c !important;': 'color: #828282 !important;').'">'. get_woocommerce_currency_symbol() . number_format($product->get_variation_sale_price('min', true)) . ' | |
</bdi> | |
</span> | |
</ins> | |
'; | |
$price .= ' | |
<span class="en-del" style="font-size: 18px !important;color: #828282 !important;"> | |
Was | |
<del aria-hidden="true" style="font-size: 18px !important;"> | |
<span class="woocommerce-Price-amount amount" style="font-size: 18px !important;color: #828282!important;"> | |
<bdi style="color: #828282 !important;font-size: 18px !important;"> | |
'. get_woocommerce_currency_symbol() . number_format($product->get_variation_regular_price('max', true)) . ' | |
</bdi> | |
</span> | |
</del> | |
</span> | |
'; | |
} else { | |
$price = ' | |
<ins class="en-ins" style="display:block;font-size: 22px !important;"> | |
<span class="woocommerce-Price-amount amount" style="font-size: 22px !important;'.(is_singular('product') ? 'color: #c8791c !important;': 'color: #828282 !important;').'"> | |
'.$from.' | |
<bdi style="font-size: 22px !important;'.(is_singular('product') ? 'color: #c8791c !important;': 'color: #828282 !important;').'">' . get_woocommerce_currency_symbol() . number_format($product->get_variation_sale_price('min', true)) . ' | |
</bdi> | |
</span> | |
</ins> | |
'; | |
} | |
return $price; | |
} else { | |
return $price; | |
} | |
// } | |
} | |
to show same html in single product price in variation prodcut | |
let remove_first_part = `<span class="price"><del aria-hidden="true"><span class="woocommerce-Price-amount amount"><bdi><span class="woocommerce-Price-currencySymbol">$</span>`; | |
let remove_middle_part = `</bdi></span></del> <ins><span class="woocommerce-Price-amount amount"><bdi><span class="woocommerce-Price-currencySymbol">$</span>`; | |
let remove_last_part = `</bdi></span></ins></span>`; | |
let variation_price_html = variation.price_html; | |
let removed_i1 = variation_price_html.replace(remove_first_part,''); | |
let removed_i2 = removed_i1.replace(remove_middle_part,'--'); | |
let removed_i3 = removed_i2.replace(remove_last_part,''); | |
let price_array = removed_i3.split("--"); | |
let en_price_html = `<p class="price"> | |
<ins class="en-ins" style="display:block;font-size: 22px !important;"> | |
<span class="woocommerce-Price-amount amount" style="font-size: 22px !important;color: #000 !important;"> | |
<bdi style="font-size: 22px !important;color: #000 !important;"> | |
$`+price_array[1]+` | |
</bdi> | |
</span> | |
</ins> | |
<span class="en-del" style="font-size: 18px !important;color: #828282 !important;"> | |
Was | |
<del aria-hidden="true" style="font-size: 18px !important;"> | |
<span class="woocommerce-Price-amount amount" style="font-size: 18px !important;color: #828282!important;"> | |
<bdi style="font-size: 18px !important; color: #828282 !important;">$`+price_array[0]+` | |
</bdi> | |
</span> | |
</del> | |
</span> | |
</p>`; | |
$price.html(en_price_html); | |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment