For custom taxonomies, including Product Categories, you should use the tax_query
argument:
$args = array(
'post_type' => 'product',
'posts_per_page' => 12,
'tax_query' => array(
array(
'taxonomy' => 'product_cat',
'terms' => 40,
),
),
);