Kleine decimalen in WooCommerce prijzen
De prijs in bijvoorbeeld 20px en de sup prijs achter de comma in 16px? Met deze snippet voeg je een class toe aan de sup prijs en kun je deze daarna los stylen.
//Create sup price
add_filter( ‘formatted_woocommerce_price’, ‘set_woo_decimal_price’, 10, 5 );
function set_woo_decimal_price( $formatted_price, $price, $decimal_places, $decimal_separator, $thousand_separator ) {
//Display normal format in backend
if(!is_admin()){
//Format the price
$unit = number_format( intval( $price ), 0, $decimal_separator, $thousand_separator );
$decimal = sprintf( ‘%02d’, ( $price – intval( $price ) ) * 1000 );
//if statement, Price may get rounded wrong otherwise
if(strlen($decimal)!==2){
$correct_dec = round($decimal,-1)/10;
}
else{
$correct_dec = $decimal;
}
//return new formated price for frontend
return $unit . $decimal_separator. ‘‘ .$correct_dec . ‘‘;
}
else{
// return normal format in admin
return $formatted_price;
}
}
Voeg eventueel dit nog toe aan je stylesheet:
.product-info sup {
font-size: 12px;
}