• Resolved dbinda

    (@danielbinda)


    I use the excellent translation plugin Falang to translate my bilingual French/English Woocommerce site. Its translation function was not working with the “YITH WooCommerce Compare” plugin version 2.22.0.

    As soon as a product was added with the “Add to compare” button, the “Compare produtcs” popup window always displayed a wrong English Description of another product in the shop (always the first one on the home page).

    The developer of the Falang plugin found the cause and the solution directly in the file /wp-content/plugins/yith-woocommerce-compare/includes/class.yith-woocompare-frontend.php

    He will send you his detailed explanation.

    The page I need help with: [log in to see the link]

Viewing 6 replies - 1 through 6 (of 6 total)
  • Hi, im’ Stéphane from Falang.

    Falang use the_content , the_title filter to translate dynamicly the data but the problem with “the_content” filter

    apply_filters( 'the_content', string $content )

    There are no $post or $post_id param’s , in the method

    public function get_products_list( $products = array() )

    you make a loop on $product_ id , but the global $post is not set and it’s not possible to use the filter , there are 2 ways to fix this , the problem occur only on $description, i prefer the second

    1 ) add a parameter $product_id to your method

    $product->fields[ $field ] = apply_filters( 'yith_woocompare_products_description', $description );

    2) set the global post during the loop , here is the global function with

    		public function get_products_list( $products = array() ) {
                global $post;//sbou
                $list = array();
    
    			if ( empty( $products ) ) {
    				$products = $this->products_list;
    			}
    
    			$products = apply_filters( 'yith_woocompare_exclude_products_from_list', $products );
    			$fields   = $this->fields( $products );
    
    			foreach ( $products as $product_id ) {
    
    				$product = $this->wc_get_product( $product_id );
    				if ( ! $product ) {
    					continue;
    				}
    
    				$post = get_post($product_id);//sbou
                    setup_postdata( $post );//sbou
    
    				$product->fields = array();
    
    				// Custom attributes.
    				foreach ( $fields as $field => $name ) {
    
    					switch ( $field ) {
    						case 'title':
    							$product->fields[ $field ] = $product->get_title();
    							break;
    						case 'price':
    							$product->fields[ $field ] = $product->get_price_html();
    							break;
    						case 'image':
    							$product->fields[ $field ] = absint( $product->get_image_id() );
    							break;
    						case 'description':
    							$description               = apply_filters( 'woocommerce_short_description', $product->get_short_description() );
    							$product->fields[ $field ] = apply_filters( 'yith_woocompare_products_description', $description );
    							break;
    						case 'stock':
    							$availability = $product->get_availability();
    							if ( empty( $availability['availability'] ) ) {
    								$availability['availability'] = __( 'In stock', 'yith-woocommerce-compare' );
    							}
    							$product->fields[ $field ] = sprintf( '<span>%s</span>', esc_html( $availability['availability'] ) );
    							break;
    						case 'sku':
    							$sku = $product->get_sku();
    							if ( ! $sku ) {
    								$sku = '-';
    							}
    							$product->fields[ $field ] = $sku;
    							break;
    						case 'weight':
    							$weight = $product->get_weight();
    							$weight = $weight ? ( wc_format_localized_decimal( $weight ) . ' ' . esc_attr( get_option( 'woocommerce_weight_unit' ) ) ) : '-';
    
    							$product->fields[ $field ] = sprintf( '<span>%s</span>', esc_html( $weight ) );
    							break;
    						case 'dimensions':
    							$dimensions = function_exists( 'wc_format_dimensions' ) ? wc_format_dimensions( $product->get_dimensions( false ) ) : $product->get_dimensions();
    							if ( ! $dimensions ) {
    								$dimensions = '-';
    							}
    
    							$product->fields[ $field ] = sprintf( '<span>%s</span>', esc_html( $dimensions ) );
    							break;
    						default:
    							if ( taxonomy_exists( $field ) ) {
    								$product->fields[ $field ] = array();
    								$terms                     = get_the_terms( $product_id, $field );
    								if ( ! empty( $terms ) ) {
    									foreach ( $terms as $term ) {
    										$term                        = sanitize_term( $term, $field );
    										$product->fields[ $field ][] = $term->name;
    									}
    								}
    								$product->fields[ $field ] = implode( ', ', $product->fields[ $field ] );
    							} else {
    								do_action_ref_array( 'yith_woocompare_field_' . $field, array( $product, &$product->fields ) );
    							}
    							break;
    					}
    				}
    
    				$list[ $product_id ] = $product;
    
                    wp_reset_postdata();//sbou
    			}
    
    			return $list;
    		}
    Plugin Support Giuseppe Madaudo

    (@askmagic)

    Hi @sbouey and @danielbinda ,

    thank you for send us the fix, we will check soon and send an update of the plugin soon as possible.

    Hi, Thanks for the feedback, keep me informed of the solution you will implement 1) or 2) for the 1) i have to make a change in Falang with this new filter.

    Stéphane

    Plugin Support crodriguez1991

    (@crodriguez1991)

    Hello there,

    I hope you’re doing well :D.

    We added the suggested changes and it will be added in the next release.

    We added the first solution and added $product as a second parameter

    							$product->fields[ $field ] = apply_filters( 'yith_woocompare_products_description', $description, $product );

    I hope it helps you.

    Have a good day.

    Hi,

    Thanks for the feedback , i will add the filter in Falang Pro to support this new filter and make Falang work with YITH WooCommerce Compare

    Plugin Support crodriguez1991

    (@crodriguez1991)

    Hello there,

    I’m glad now the plugins will be integrated.

    I’m going to close this topic but don’t hesitate to contact us if you have any other question or problem, we’ll be happy to help us.

    Have a good day.

Viewing 6 replies - 1 through 6 (of 6 total)
  • The topic ‘Translation error with the Falang translation plugin’ is closed to new replies.