How to apply action the_post to the post that is only being mainly displayed

Okay. Here we go!

I needed this to be implemented within only one plugin, not inside the template.

So I found out how to get the ID of current post outside the loop.
The great function get_queried_object() and get_queried_object_id() will seal the deal!

It might not seem the quickiest way (it queries the database) but in my case it is a perfect solution since I’m running this code not for every page and not every time it’s loaded.

And the final code is

function do_some_modifications($post)
{
    if (is_singular('product') and get_queried_object_id() == $post->ID) {
        // do some action
    }
    return $post;
}
add_action('the_post', 'do_some_modifications');