• Resolved tayssir.ch

    (@tayssirch)


    Hello, I am using your plugin and WPML.

    I have product title in English :
    BravoProdigy Impact Dot Peen Module
    and in Arabic:
    ??? ??? ?? ????? ?????? ?????

    My Relevanssi settings is WPML Limit results to current language. enabled
    there is any way to ” If user was in English language, and he searched for ” ??? ” the product appear in search results ?
    same if was in Arabic language , if he searched for “Dot peen” for example

    the issue, i can’t disable the option ” Limit results to current language. ” because i will start getting duplicate results if a product has same name in English and Arabic

    I tried this code, but not able to achieve my goal

    add_filter( 'relevanssi_content_to_index', 'rlv_index_titles', 10, 2 );
    function rlv_index_titles( $content, $post ) {
    if ( 'product' === $post->post_type ) {
    $args = array(
    'post_parent' => $post->ID,
    'post_type' => 'product',
    'posts_per_page' => -1
    );
    $products = get_posts( $args );
    if ( ! empty( $products ) ) {
    foreach ( $products as $product ) {
    $arabic_product_id = apply_filters( 'wpml_object_id', $product->get_id(), 'product', false, 'ar' );
    $arabic_product = wc_get_product( $arabic_product_id );
    $arabic_title = $arabic_product->get_title();
    
    $english_product_id = apply_filters( 'wpml_object_id', $product->get_id(), 'product', false, 'en' );
    $english_product = wc_get_product( $english_product_id );
    $english_title = $english_product->get_title();
    $content .= " $arabic_title";
    $content .= " $english_title";
    }
    }
    }
    return $content;
    }

    do you have any suggestions ?

Viewing 3 replies - 1 through 3 (of 3 total)
  • Plugin Author Mikko Saari

    (@msaari)

    To me, this sounds like you’re on the right track. I’d recommend debugging your code to see why it’s not working because that’s the way to go.

    For starters, why are you fetching the product parents? Are you sure the products have a parent/child relationship? I’ve understood product variations are children of the parent product, but you’re not looking at variations, you’re looking at products. Do they really have parents?

    Other than that, debug the function you have to see why it’s not fetching the correct posts. From Relevanssi perspective, you’re doing the right thing.

    Thread Starter tayssir.ch

    (@tayssirch)

    Thanks for the advice, You are totally right,
    I think I should define $woocommerce or $product global before.

    But I was able to achieve my goal like this:

    add_filter( 'relevanssi_content_to_index', 'rlv_index_title', 10, 2 );
    function rlv_index_title( $content, $post ) {
    	if ( 'product' === $post->post_type ) {
                  $arabic_product_id = apply_filters( 'wpml_object_id', $post->ID, 'product', false, 'ar' );
    				if($arabic_product_id){
    			      $arabic_title      = get_the_title( $arabic_product_id );
    				}
                  $english_product_id = apply_filters( 'wpml_object_id', $post->ID, 'product', false, 'en' );
    				if($english_product_id){
    			 	  $english_title      = get_the_title( $english_product_id );
    				}
    				$content .= " $arabic_title";
    				$content .= " $english_title";   
    	}
    	return $content;
    }

    if you think i should enhance it more please advice, thank you

    Plugin Author Mikko Saari

    (@msaari)

    Nothing to enhance here, that’s perfect!

Viewing 3 replies - 1 through 3 (of 3 total)
  • The topic ‘Show product content from different language WPML, without duplication’ is closed to new replies.