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.