• Resolved screenup

    (@screenup)


    Hello there,

    I have an issue that keep poping in my logs regarding the WC_Cart class, here is the error in my logs :

    2024-01-10T09:06:31+00:00 CRITICAL Uncaught Error: Call to a member function get_tax_class() on null in /var/www/vhosts/mywebsite.com/httpdocs/wp-content/plugins/woocommerce/includes/class-wc-cart-totals.php:232 Stack trace: #0 /var/www/vhosts/mywebsite.com/httpdocs/wp-content/plugins/woocommerce/includes/class-wc-cart-totals.php(658): WC_Cart_Totals->get_items_from_cart() #1 /var/www/vhosts/mywebsite.com/httpdocs/wp-content/plugins/woocommerce/includes/class-wc-cart-totals.php(150): WC_Cart_Totals->calculate_item_totals() #2 /var/www/vhosts/mywebsite.com/httpdocs/wp-content/plugins/woocommerce/includes/class-wc-cart-totals.php(141): WC_Cart_Totals->calculate() #3 /var/www/vhosts/mywebsite.com/httpdocs/wp-content/plugins/woocommerce/includes/class-wc-cart.php(1408): WC_Cart_Totals->__construct() #4 /var/www/vhosts/mywebsite.com/httpdocs/wp-content/plugins/woocommerce/includes/class-wc-cart.php(1367): WC_Cart->calculate_totals() #5 /var/www/vhosts/mywebsite.com/httpdocs/wp-content/themes/salient/nectar/woo/cart.php(157): WC_Cart->set_quantity() #6 /var/www/vhosts/mywebsite.com/httpdocs/wp-includes/class-wp-hook.php(324): Nectar_Woo_Cart::update_cart_quantity() #7 /var/www/vhosts/mywebsite.com/httpdocs/wp-includes/class-wp-hook.php(348): WP_Hook->apply_filters() #8 /var/www/vhosts/mywebsite.com/httpdocs/wp-includes/plugin.php(517): WP_Hook->do_action() #9 /var/www/vhosts/mywebsite.com/httpdocs/wp-admin/admin-ajax.php(203): do_action() #10 {main} thrown dans /var/www/vhosts/mywebsite.com/httpdocs/wp-content/plugins/woocommerce/includes/class-wc-cart-totals.php à la ligne 232

    This seems to be related to a method called get_tax_class() receiving a null object thus leading to an error because the get_items_from_cart(), calculate_item_totals(), calculate(), and so on… cannot be executed since get_tax_class() is returning null.

    Do you know what could be causing the issue ? Does an item could have a null tax value ? If so is there anything that I could do to avoid getting this error ? For instance checking prior to execute this methos if my $object->get_tax_class() isset ?

    Thanks in advance for your replies,
    Have a great day ??

    Paul

Viewing 1 replies (of 1 total)
  • Plugin Support Shameem R. a11n

    (@shameemreza)

    Hi @screenup,

    If a product doesn’t have a tax class assigned or the tax class is somehow deleted, this could lead to a null object being returned when get_tax_class() is called.

    To resolve this issue, I suggest you check all your products to ensure they have a tax class assigned. If you have a large number of products, you might find it easier to do this directly in the database or by using a bulk editing plugin.

    Additionally, it might be a good idea to add some error handling in your code to check if the tax class exists before executing the get_tax_class() method.

    In the meantime, you can run a conflict test to help you identify the cause of the issue. More info: https://woo.com/document/how-to-test-for-conflicts/

    I hope this helps! If you need further assistance, please don’t hesitate to ask.

Viewing 1 replies (of 1 total)
  • The topic ‘Cart Fatal error in attempt to call get_tax_class() method’ is closed to new replies.