I'm in big trouble, because on live site I just discovered that our API put strange output and due to that can not sync products with our ERP and CRM. I think the problem is in this piece of code but I can not figure out how to keep it because it works on frotnend but exclude it from API Json output?
//PROCENT SPARET PÅ SIMPLE PRODUCT
add_filter( 'woocommerce_format_sale_price', 'woocommerce_custom_sales_price', 10, 3 );
function woocommerce_custom_sales_price( $price, $regular_price, $sale_price ) {
// Getting the clean numeric prices (without html and currency)
$_reg_price = floatval( strip_tags($regular_price) );
$_sale_price = floatval( strip_tags($sale_price) );
// Percentage calculation and text
$percentage = round( ( $_reg_price - $_sale_price ) / $_reg_price * 100 ).'%';
$percentage_txt = '(' . __('-', 'woocommerce' ) . $percentage . ')';
$formatted_regular_price = is_numeric( $regular_price ) ? wc_price( $regular_price ) : $regular_price;
$formatted_sale_price = is_numeric( $sale_price ) ? wc_price( $sale_price ) : $sale_price;
echo '<del>' . $formatted_regular_price . '</del> <ins>' . $formatted_sale_price ."<span class='percentage_save'>". $percentage_txt . "</span>".'</ins>';
}
And problem in output is visible here
Does anybody have idea how to quickly fix that? Thanks in advance