The issue has been resolved. This code snippet may be helpful to others who encounter similar problems.
function my_query_by_post_types1($query) {
if (is_singular('product')) {
// Get product categories
$terms = get_the_terms(get_the_ID(), 'product_cat');
if ($terms) {
// Get all category names
$category_names = wp_list_pluck($terms, 'name');
if ($category_names) {
$query->set('post_type', 'news');
$query->set('meta_query', array(
array(
'key' => 'product_category',
'value' => '"' . implode('","', $category_names) . '"',
'compare' => 'LIKE'
)
));
}
}
}
}
add_action('elementor/query/product_related_news', 'my_query_by_post_types1');