If you want to know whether a post (page, product, any custom post type) is currently being edited, use wp_check_post_lock( $post_id ). If a user is currently editing the post, it returns the user's ID. Otherwise it returns false, and you can proceed to edit it.
If you want to mark a post as being edited, use wp_set_post_lock( $post_id ). Calling this will silently override any existing lock, so check first. You should call this function every two minutes, or more often, while editing is in progress, because locks expire after 150 seconds.
This is all implemented via a wp_postmeta entry with meta_key '_edit_lock'
and meta_value 'timestamp:userid'
. The timestamp is the time the lock was set. For example, '1667470754:123'
means userid 123 locked the post at time Thu Nov 03 2022 10:19:14Z. But avoid hitting the wp_postmeta table directly for this. The value may be cached.
You can use the check_post_lock_window filter to alter the lock expiration time if need be.
The _admin_notice_post_locked() function puts up a notice about a post being locked. But this function is designed for use within WordPress core admin pages, so it may not work for you.