Last active
May 2, 2019 07:27
-
-
Save acanza/4b6942e732fb54dce34420ef62a657eb to your computer and use it in GitHub Desktop.
Muestra el porcentaje de descuento en lugar de la etiqueta "¡Oferta!"
This file contains hidden or 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
// Muestra el porcentaje de descuento en lugar de la etiqueta "¡Oferta!" | |
add_filter( 'woocommerce_sale_flash', 'show_discount_percentage_instead_of_sale_flash', 10, 3 ); | |
function show_discount_percentage_instead_of_sale_flash( $text, $post, $product ) { | |
if( $product->get_type() == 'variable' ){ | |
$regular_price = $product->get_variation_regular_price( 'max' ); | |
$sale_price = $product->get_variation_sale_price( 'min' ); | |
}else{ | |
$regular_price = $product->get_regular_price(); | |
$sale_price = $product->get_sale_price(); | |
} | |
if ( $regular_price && $sale_price ) { | |
$percentage = round( ( ( $regular_price - $sale_price ) / $regular_price ) * 100 ); | |
$text = '<span class="onsale">'. __(' Ahorras un ', 'woocommerce' ). $percentage . '%</span>'; | |
} | |
return $text; | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment