Fix warning when order edit lock is released mid page load (#41278)

This commit is contained in:
Jorge A. Torres 2023-11-08 15:12:55 +00:00 committed by GitHub
parent b608d0e79e
commit ba43dce533
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
3 changed files with 10 additions and 2 deletions

View File

@ -0,0 +1,4 @@
Significance: patch
Type: fix
Prevent PHP warning when order lock is released during page load.

View File

@ -237,6 +237,10 @@ class Edit {
// Order updated message.
$this->message = 1;
// Claim lock.
$edit_lock = wc_get_container()->get( EditLock::class );
$edit_lock->lock( $this->order );
$this->redirect_order( $this->order );
}

View File

@ -166,9 +166,9 @@ class EditLock {
* @return void
*/
public function render_dialog( $order ) {
$locked = $this->is_locked_by_another_user( $order );
$lock = $this->get_lock( $order );
$user = get_user_by( 'id', $lock['user_id'] );
$user = $lock ? get_user_by( 'id', $lock['user_id'] ) : false;
$locked = $user && ( get_current_user_id() !== $user->ID );
$edit_url = wc_get_container()->get( \Automattic\WooCommerce\Internal\Admin\Orders\PageController::class )->get_edit_url( $order->get_id() );