• Same error as this previous topic, which is closed to replies: https://wordpress.org/support/topic/division-by-zero-error-23/ by @davekuhar

    If an order line item’s quantity is 0, a division by zero error is thrown:

    Uncaught DivisionByZeroError: Division by zero in /[...]/wp-content/plugins/taxjar-simplified-taxes-for-woocommerce/includes/class-taxjar-order-record.php:272 

    While there is obviously an underlying issue somewhere else causing the quantity of some items (intermittently in my case) to be 0, this plugin should ideally protect from a division by zero error here.

    Changing this line indicated by the error:

    $unit_price = NumberUtil::round( $item->get_subtotal(), wc_get_price_decimals() ) / $quantity;

    To this:

    $unit_price = $quantity ? NumberUtil::round( $item->get_subtotal(), wc_get_price_decimals() ) / $quantity : 0;

    Fixes the problem, at least with TaxJar.

    • This topic was modified 1 year, 6 months ago by Cory Hughart. Reason: tag original topic author

The topic ‘Division by Zero Error (with fix)’ is closed to new replies.