Woocommerce: limit user to see only the products he created

I believe changing the following conditional:

if( !current_user_can( 'manage_options' ) )

to this one:

if( !current_user_can( 'manage_options' ) && 'product' === $query->get( 'post_type' ) )

would do it.

Brief explanation: I added a second condition which checks if the query is for WooCommerce products where the post type is product.

UPDATE

If you want to make certain that the code runs only on the products page (WooCommerce → Products), then you can (remove the global $pagenow; and) change this:

if( 'edit.php' != $pagenow || !$query->is_admin )

to this one:

if( !$query->is_admin || 'edit-product' !== get_current_screen()->id )

And instead of relying on the global $user_ID, you should probably use get_current_user_id(): $query->set( 'author', get_current_user_id() ); 🙂