taxjar-woocommerce-plugin
taxjar-woocommerce-plugin copied to clipboard
PHP 8 Fatal Error
I'm getting a fatal error running this plugin in PHP 8. The problem seems to be in this function: https://github.com/taxjar/taxjar-woocommerce-plugin/blob/master/includes/TaxCalculation/class-order-tax-applicator.php#L209-L215
This seems to fix the problem:
private function get_order_total() {
$cart_total = $this->get_cart_total_for_order();
$tax_total = $this->order->get_cart_tax() + (float) $this->order->get_shipping_tax();
$fees_total = $this->order->get_total_fees();
$shipping_total = (float) $this->order->get_shipping_total();
return $cart_total + $tax_total + $fees_total + $shipping_total;
}
$order->get_shipping_total
and $order->get_shipping_tax
both return a string or null.
Here is the error:
[17-Oct-2022 11:49:08 UTC] PHP Fatal error: Uncaught TypeError: Unsupported operand types: float + string in /nas/content/live/site/wp-content/plugins/taxjar-simplified-taxes-for-woocommerce/includes/TaxCalculation/class-order-tax-applicator.php:214
Stack trace:
#0 /nas/content/live/site/wp-content/plugins/taxjar-simplified-taxes-for-woocommerce/includes/TaxCalculation/class-order-tax-applicator.php(175): TaxJar\Order_Tax_Applicator->get_order_total()
#1 /nas/content/live/site/wp-content/plugins/taxjar-simplified-taxes-for-woocommerce/includes/TaxCalculation/class-order-tax-applicator.php(61): TaxJar\Order_Tax_Applicator->update_totals()
#2 /nas/content/live/site/wp-content/plugins/taxjar-simplified-taxes-for-woocommerce/includes/TaxCalculation/class-tax-applicator.php(46): TaxJar\Order_Tax_Applicator->apply_new_tax()
#3 /nas/content/live/site/wp-content/plugins/taxjar-simplified-taxes-for-woocommerce/includes/TaxCalculation/class-tax-calculator.php(271): TaxJar\Tax_Applicator->apply_tax(Object(TaxJar\Tax_Details))
#4 /nas/content/live/site/wp-content/plugins/taxjar-simplified-taxes-for-woocommerce/includes/TaxCalculation/class-tax-calculator.php(188): TaxJar\Tax_Calculator->apply_tax()
#5 /nas/content/live/site/wp-content/plugins/taxjar-simplified-taxes-for-woocommerce/includes/class-taxjar-tax-calculation.php(60): TaxJar\Tax_Calculator->maybe_calculate_and_apply_tax()
#6 /nas/content/live/site/wp-content/mu-plugins/site/includes/Admin/BulkOrders/CreateSubscriptions.php(228): TaxJar_Tax_Calculation->maybe_calculate_order_taxes(true, Object(WC_Subscription))
#7 /nas/content/live/site/wp-includes/class-wp-hook.php(307): Site\Admin\BulkOrders\CreateSubscriptions->create_subscription('')
#8 /nas/content/live/site/wp-includes/class-wp-hook.php(331): WP_Hook->apply_filters('', Array)
#9 /nas/content/live/site/wp-includes/plugin.php(476): WP_Hook->do_action(Array)
#10 /nas/content/live/site/wp-admin/admin-ajax.php(187): do_action('wp_ajax_create_...')
#11 {main}
Next TypeError: TaxJar\Order_Tax_Calculation_Result_Data_Store::update(): Argument #1 ($calculation_result) must be of type TaxJar\Tax_Calculation_Result, null given, called in /nas/content/live/site/wp-content/plugins/taxjar-simplified-taxes-for-woocommerce/includes/TaxCalculation/class-tax-calculator.php on line 193 and defined in /nas/content/live/site/wp-content/plugins/taxjar-simplified-taxes-for-woocommerce/includes/TaxCalculation/class-order-tax-calculation-result-data-store.php:42
Stack trace:
#0 /nas/content/live/site/wp-content/plugins/taxjar-simplified-taxes-for-woocommerce/includes/TaxCalculation/class-tax-calculator.php(193): TaxJar\Order_Tax_Calculation_Result_Data_Store->update(NULL)
#1 /nas/content/live/site/wp-content/plugins/taxjar-simplified-taxes-for-woocommerce/includes/class-taxjar-tax-calculation.php(60): TaxJar\Tax_Calculator->maybe_calculate_and_apply_tax()
#2 /nas/content/live/site/wp-content/mu-plugins/site/includes/Admin/BulkOrders/CreateSubscriptions.php(228): TaxJar_Tax_Calculation->maybe_calculate_order_taxes(true, Object(WC_Subscription))
#3 /nas/content/live/site/wp-includes/class-wp-hook.php(307): Site\Admin\BulkOrders\CreateSubscriptions->create_subscription('')
#4 /nas/content/live/site/wp-includes/class-wp-hook.php(331): WP_Hook->apply_filters('', Array)
#5 /nas/content/live/site/wp-includes/plugin.php(476): WP_Hook->do_action(Array)
#6 /nas/content/live/site/wp-admin/admin-ajax.php(187): do_action('wp_ajax_create_...')
#7 {main}
thrown in /nas/content/live/site/wp-content/plugins/taxjar-simplified-taxes-for-woocommerce/includes/TaxCalculation/class-order-tax-calculation-result-data-store.php on line 42
Same issue happening on one of my client's sites. Now that PHP 7.x is fully deprecated, this is a high priority issue!
@dallendalton Is this repo still active?
@slewisma Did you try to update WooCommerce to the latest version? I did and it looks like this issue is gone.
I think this commit solved the issue of the function returning an empty string: https://github.com/woocommerce/woocommerce/commit/ad30c6146396c264c4d7c4e55bfcf29ea84df175#diff-8261b720d84fcccf0d768b1a4114051cd1d52a4661b320a28b5144abefaf41c8R668