fbpx

Home Forums Booster Plus Customer Forum {Proposed FIX} Uncaught Error: Call to a member function get_user_id()

Tagged: 

Viewing 2 posts - 1 through 2 (of 2 total)
  • Author
    Posts
  • #47412
    Gerard
    Participant

    After updating to 7.1.2. there is an Uncaught Error appearing when adding a product to cart with redirect to cart. This only happens for users who are not logged in.

    Uncaught Error: Call to a member function get_user_id() in class-wcj-orders-shortcodes line 236

    Original code (including line 236):
    if ( ! current_user_can( ‘manage_woocommerce’ ) ) {
    $order = wc_get_order( $atts[‘order_id’] ); // returns false
    if ( isset( $order ) && ! empty( $order->get_user_id() ) ) {. // false->get_user_id() returns Fatal error
    if ( $order->get_user_id() !== get_current_user_id() ) {
    return false;
    }
    } else {
    return false;
    }
    }

    Code fix:
    if ( ! current_user_can( ‘manage_woocommerce’ ) ) {
    $order = wc_get_order( $atts[‘order_id’] );
    if ( ! empty( $order ) ) {
    if ( ! empty( $order->get_user_id() ) ) {
    if ( $order->get_user_id() !== get_current_user_id() ) {
    return false;
    }
    }
    } else {
    return false;
    }
    }

    This solves the fatal error. But I’m not sure if the proposed fix is causing other problems.

    #47416
    David G
    Participant

    Hi @enteractive ,

    Thanks for reaching out to us.

    We are checking the issue from our side and will get back to you with the solution soon.

Viewing 2 posts - 1 through 2 (of 2 total)
  • You must be logged in to reply to this topic.