mollie / WooCommerce

Official Mollie extension for WooCommerce
https://wordpress.org/plugins/mollie-payments-for-woocommerce/
Other
129 stars 52 forks source link

Fatal error on order - unable to make a division by zero #907

Open MKlblangenois opened 3 months ago

MKlblangenois commented 3 months ago

When we've order that has specific vat rates on shipping or even equals to zero, we got a fatal error when customer try to make complete checkout.

In log, we got a "unable to make a division by zero" and I've fixed that by adding the next line inside the plugin file, but I'm not sure that fix doesn't affect other parts of code:

./src/Payment/OrderLines.php#528

 /**
     * Get shipping method tax rate.
     *
     * @since 1.0
     *
     * @access private
     *
     * @return float|int $shipping_vat_rate Tax rate for selected shipping method.
     *
     * @psalm-return 0|float
     */
    private function get_shipping_vat_rate() {
        $shipping_vat_rate = 0;

+       if (WC()->cart->shipping_tax_total > 0 && WC()->cart->shipping_total > 0) {
            $shipping_vat_rate = round(WC()->cart->shipping_tax_total / WC()->cart->shipping_total, 2) * 100;
+      }

        return $shipping_vat_rate;
    }