Home Forums WoodMart support forum Fatal error in Woodmart related to the Dynamic Discounts module

Fatal error in Woodmart related to the Dynamic Discounts module

Viewing 5 posts - 1 through 5 (of 5 total)
  • Author
    Posts
  • #713054

    joelmellin
    Participant

    Hello,

    I am reporting a recurring fatal error in Woodmart related to the Dynamic Discounts module.

    Environment:
    – Theme: Woodmart (parent theme active via woodmart-child)
    – WooCommerce: 10.5.3
    – WordPress: current production site
    – Issue occurs intermittently, mainly during WooCommerce cart/admin-AJAX related actions

    Recurring fatal error found in WooCommerce fatal logs:
    Uncaught Error: Call to a member function get_type() on null
    File:
    /wp-content/themes/woodmart/inc/integrations/woocommerce/modules/dynamic-discounts/class-main.php:107

    Relevant code:
    foreach ( $cart->get_cart() as $cart_item ) {
    if ( ‘variation’ !== $cart_item[‘data’]->get_type() ) {
    continue;
    }
    }

    The problem is that $cart_item[‘data’] is sometimes null, so calling get_type() causes a fatal error.

    Log excerpt:
    CRITICAL Uncaught Error: Call to a member function get_type() on null in /home/…/wp-content/themes/woodmart/inc/integrations/woocommerce/modules/dynamic-discounts/class-main.php:107

    Backtrace summary:
    – XTS\Modules\Dynamic_Discounts\Main->calculate_discounts()
    – WC_Cart->calculate_totals()
    – woodmart_update_cart_item()
    – wp-admin/admin-ajax.php

    This has happened repeatedly on multiple dates, not just once.

    It looks like the Dynamic Discounts code assumes that every cart item always contains a valid WC_Product object in $cart_item[‘data’], but in my case at least one cart row sometimes contains null. A defensive check before calling get_type() seems necessary.

    Could you please confirm:
    1. whether this is a known compatibility bug,
    2. whether it has already been fixed in a newer Woodmart release,
    3. or whether you can provide a patch/hotfix for class-main.php.

    I would appreciate a fix that survives theme updates, since I do not want to patch the parent theme directly.

    Best regards

    #713119

    Artem Temos
    Keymaster
    Xtemos team

    Hello,

    Please send us your admin access so we can check what is wrong.

    Kind Regards

    #713341

    joelmellin
    Participant

    Ok!

    #713376

    Artem Temos
    Keymaster
    Xtemos team

    We don’t see the error now and can’t reproduce it. Cart items always have WC_Product type. We need to be able to reproduce this error to understand why the type is wrong there.

    #713412

    joelmellin
    Participant

    Thank you.

    I understand that cart items are expected to contain a valid WC_Product object. My point is not that this should normally be null, but that your code currently assumes it can never be null and crashes fatally when that assumption fails.

    So I agree that there may be an upstream cause as well, for example a broken cart/session row or a compatibility issue with another plugin. However, the current Woodmart code still fatally crashes instead of handling that edge case safely.

    The error is intermittent and happens during cart recalculation / admin-AJAX related flows, so it is difficult to reproduce on demand.

    I will now add extra logging on my side to capture the exact cart item payload when this happens, including cart item key, product_id, variation_id, quantity, request URI, AJAX context and session/cart state before Woodmart Dynamic Discounts runs.

    Once I capture that, I will send you the relevant log excerpt.

    That said, I still believe a defensive check before calling get_type() would be appropriate, because a theme-level fatal error should ideally not occur even if another plugin or cart row is malformed.

Viewing 5 posts - 1 through 5 (of 5 total)