разделение предупреждений по нулевой категории

Я с этой функцией, на странице единого продукта она работает нормально. Но на странице категории он продолжает говорить мне: «ВНИМАНИЕ: РАЗДЕЛЕНИЕ НА НОЛЬ В». Спасибо за любую помощь!

add_filter( 'woocommerce_sale_price_html', 'woocommerce_custom_sales_price', 10, 2 );

function woocommerce_custom_sales_price( $price, $product ) {

$percentage = round( ( ( $product->regular_price - $product->sale_price ) / $product->regular_price ) * 100 );

if ($percentage < 0) { return null;}

else {

if (is_product()) {
return $price . sprintf( __('<br><span style="font-size:14px;font-weight:bold; color:#ef4136">-%s DE DESCONTO</span>', 'woocommerce' ), $percentage . '%' );}

else {
return $price . sprintf( __('<span style="font-size:14px;font-weight:bold; color:#ef4136">-%s DE DESCONTO</span>', 'woocommerce' ), $percentage . '%' );}
}
}

0

Решение

        function woocommerce_custom_sales_price( $price, $product ) {

if($product->regular_price > 0 ){ // Do a check if you have set the regular price of product.
$percentage = round( ( ( $product->regular_price - $product->sale_price ) / $product->regular_price ) * 100 );
}

if ($percentage < 0) { return null;}

else {

if (is_product()) {
return $price . sprintf( __('<br><span style="font-size:14px;font-weight:bold; color:#ef4136">-%s DE DESCONTO</span>', 'woocommerce' ), $percentage . '%' );}

else {
return $price . sprintf( __('<span style="font-size:14px;font-weight:bold; color:#ef4136">-%s DE DESCONTO</span>', 'woocommerce' ), $percentage . '%' );}
}
}
0

Другие решения

Других решений пока нет …

По вопросам рекламы ammmcru@yandex.ru
Adblock
detector