• Resolved Lara

    (@laraborgi)


    When attempting to create an order from the WooCommerce backend (admin panel), the plugin throws a fatal error:

    Fatal error: Uncaught Error: Call to a member function get() on null in
    /includes/class-hc-wcma-checkout.php:288

    The hc_wcma_get_session_or_post() method in class-hc-wcma-checkout.php (Line: ~288) attempts to access WC()->session->get() without checking if the session object exists. In the WordPress admin context (when creating orders manually), WC()->session is null because there is no active user session, causing the fatal error.

    The solutions is to add a null check before attempting to access the WooCommerce session object. The session should only be accessed if it exists (frontend checkout), otherwise fall back to POST data.

    My proposed fixed is to replace the hc_wcma_get_session_or_post() method with the following code:

    private static function hc_wcma_get_session_or_post( $session_key, $post_key ) {

    if ( WC()->session ) {

    $value = WC()->session->get( $session_key );

    if ( ! empty( $value ) ) {

    return $value;

    }

    }

    // PHPCS:ignore WordPress.Security.NonceVerification.Missing -- Nonce verified earlier.

    return isset( $_POST[ $post_key ] ) ? sanitize_text_field( wp_unslash( $_POST[ $post_key ] ) ) : '';

    }

    The same null check should also be applied to the session clearing code in the save_new_address_from_order() method (around line 360) to prevent similar issues

Viewing 1 replies (of 1 total)
  • Plugin Author Kombiah Ramaiah

    (@kombiahrk)

    Hello @laraborgi,

    Thank you for your detailed bug report and for providing a clear explanation of the issue, including a
    proposed solution.

    You were absolutely correct. The fatal error occurred in contexts where a WooCommerce session is not initialized. I’m happy to confirm that we have addressed this by implementing the null checks you suggested. The fix has been included in the latest version of the plugin, 1.0.14, which is now available for update.

    We appreciate you taking the time to help us improve the plugin. If you’re happy with the plugin and our support, would you consider leaving us a quick rating or review? It would be a huge help.

    Best regards,
    The HappyCoders Team

Viewing 1 replies (of 1 total)

The topic ‘Fatal Error When Creating Orders from WooCommerce Admin’ is closed to new replies.