תצוגת הנחה באחוזים

PHOTO EMBED

Tue May 18 2021 19:58:55 GMT+0000 (Coordinated Universal Time)

Saved by @Shesek

add_filter( 'woocommerce_sale_flash', 'navarro_change_badge_to_percentage', 10, 3 );


function navarro_change_badge_to_percentage( $html, $post, $product ) {

	$price = intval( ( $product instanceof WC_Product_Variable ) ? $product->get_variation_regular_price() : $product->get_regular_price() );
	
	$sale = intval( ( $product instanceof WC_Product_Variable ) ? $product->get_variation_sale_price() : $product->get_sale_price() );

	$percent = floor( 100 - ( $sale * 100 / $price ) );

	return sprintf( '<div class="onsale-wrapper"><span class="onsale">%s%% %s</span></div>', $percent, __( 'הנחה', 'woocommerce' ) );

}
content_copyCOPY