Skip to content

Instantly share code, notes, and snippets.

Show Gist options
  • Save acanza/4b6942e732fb54dce34420ef62a657eb to your computer and use it in GitHub Desktop.
Save acanza/4b6942e732fb54dce34420ef62a657eb to your computer and use it in GitHub Desktop.
Muestra el porcentaje de descuento en lugar de la etiqueta "¡Oferta!"
// 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