Divide by zero error on 100% discount
-
I’m getting a divide by zero warning when I apply a 100% discount:
Warning: Division by zero in /nas/content/live/universallife/wp-content/plugins/woocommerce-fixed-quantity/classes/client-fixed-quantity-price.php on line 203
public function filter_item_price($price, $cart_item, $cart_item_key) { if (empty($cart_item['data'])) { return $price; } $_product = apply_filters('woocommerce_cart_item_product', $cart_item['data'], $cart_item, $cart_item_key); $productId = WoofixUtility::getActualId($_product); $fixedPriceData = WoofixUtility::isFixedQtyPrice($productId); if ($fixedPriceData !== false) { $discount = 0; foreach ($fixedPriceData['woofix'] as $disc) { if ($disc['woofix_qty'] == $cart_item['quantity']) { $discount = $disc['woofix_disc']; } } $itemPrice = $_product->get_price(); $discprice = wc_price($itemPrice); //this is line 203 $oldprice = ($itemPrice * 100) / (100 - $discount); //this is line 203^^ $oldprice = wc_price($oldprice); if ($oldprice == $discprice) { $price = "<span class='discount-info'><span class='new-price'>$discprice</span></span>"; } else { $price = "<span class='discount-info'>" . "<span class='old-price'><del>$oldprice</del></span> " . "<span class='new-price'><strong>$discprice</strong></span></span>"; } } return $price; }
Viewing 4 replies - 1 through 4 (of 4 total)
Viewing 4 replies - 1 through 4 (of 4 total)
- The topic ‘Divide by zero error on 100% discount’ is closed to new replies.