How to get current product category ID in product archive page

If I am on a product archive page then how can I get current product category ID in product archive page. I am using this but no result:

global $wp_query;
$category_name = $wp_query->query_vars['product_cat'];
$category_object = get_term_by('name', $category_name, 'product_cat');
$category_id = $category_object->term_id;

Solutions Collecting From Web of "How to get current product category ID in product archive page"