Skip to content

Instantly share code, notes, and snippets.

Embed
What would you like to do?
WooCommerce Angebot mit Prozenten angeben
if ( !function_exists( 'evolution_custom_sales_price' ) ) :
/**
* Zeigt dem Kunden Prozente, die durch ein Songerangebot gespart werden
*
* @add filter to products
*
* @return filter
*/
function evolution_custom_sales_price( $price, $regular_price, $sale_price ) {
$percentage = round( ( $regular_price - $sale_price ) / $regular_price * 100 ).'%';
$percentage_txt = __(' Sie sparen ', 'evolution' ).$percentage; // Text anpassen
$price = '<del>' . ( is_numeric( $regular_price ) ? wc_price( $regular_price ) : $regular_price ) . '</del> <ins>' . ( is_numeric( $sale_price ) ? wc_price( $sale_price ) . $percentage_txt : $sale_price . $percentage_txt ) . '</ins>';
return $price;
}
add_filter( 'woocommerce_format_sale_price', 'evolution_custom_sales_price', 10, 3 );
endif;
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment