Woocommerce & Polylang: common comments under product in different languages

I developed a WordPress multilingual site with shop, based on Woocommerce plugin.
The task was to make all comments appear under all languages’ versions of a product.
Tried a lot of possible solutions and finally came to bare mysql request.

File woocommerce/single-product-reviews.php contains the line:

wp_list_comments( array( 'callback' => 'woocommerce_comments', 'avatar_size' => 75 ) );

I changed it to the following:

$languages = icl_get_languages();

	$post = get_post(  );
	$type = $post->post_type;
    $post_ID = $post->ID;
    foreach($languages as $l) {
	$postId = pll_get_post($post_ID, $l['language_code']);
        array_push($lng_ids, $postId) ;

$string_lng_ids=implode(",", $lng_ids); //build ID string for sql query

global $wpdb;
select *
from wp_comments
inner join wp_posts on wp_posts.ID=wp_comments.comment_post_ID
where comment_approved=1
and wp_posts.ID in ($string_lng_ids)
order by comment_date desc



wp_list_comments( array( 'callback' => 'woocommerce_comments', 'avatar_size' => 75 ) , $comments);

That’s it, I got all the related comments under all versions of the same products.

Leave a Reply

%d bloggers like this: