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;
}