php - warning division by zero woocommerce category -
i'm function, on single product page works fine. on category page keeps telling me: 'warning: division 0 in'. help!
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 . '%' );} } }
function woocommerce_custom_sales_price( $price, $product ) { if($product->regular_price > 0 ){ // check if have set 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 . '%' );} } }
Comments
Post a Comment