Get post id in wordpress action?

I haven’t tested so I’m providing you with two possibilities, Inside a loop, use the following:

$post_id = get_the_ID();

Outside a loop, use the following:

global $wp_query;
$post_id = $wp_query->post->ID;

Or:

global $post;
$post_id = $post->ID

Or you can pass the post ID in a function, much like

function my_function($post_id){
    // code
}