Panoramica del problema
Quando usi YITH WooCommerce Compare con WPML, potresti riscontrare i seguenti problemi nelle pagine in una lingua secondaria:
- La tabella di confronto si apre nella lingua predefinita.
- Un prodotto aggiunto in una pagina in un’altra lingua mostra il suo nome in quella lingua.
- Le righe degli attributi mostrano le etichette degli attributi nella lingua predefinita.
- Il foglio di stile del plugin non viene caricato, quindi i pulsanti e la tabella non hanno stili.
Soluzione alternativa
Aggiungi questo codice al file functions.php del tuo tema o a un plugin per frammenti di codice:
PHP
// The comparison table opens in the current language.
add_filter( 'yith_woocompare_view_table_url', function ( $url ) {
return apply_filters( 'wpml_permalink', $url, apply_filters( 'wpml_current_language', null ) );
} );
// The table shows the products of the current language.
add_filter( 'yith_woocompare_products_list', function ( $ids ) {
return array_values( array_unique( array_map( function ( $id ) {
return (int) apply_filters( 'wpml_object_id', $id, get_post_type( $id ) ?: 'product', true );
}, (array) $ids ) ) );
} );
// The attribute rows show the translated attribute labels.
add_filter( 'yith_woocompare_filter_table_fields', function ( $fields ) {
foreach ( array_keys( (array) $fields ) as $field ) {
if ( 0 === strpos( (string) $field, 'pa_' ) && taxonomy_exists( $field ) ) {
$fields[ $field ] = wc_attribute_label( $field );
}
}
return $fields;
} );
// The plugin stylesheet loads on secondary-language pages.
add_filter( 'yith_woocompare_asset_url', function ( $url, $asset_path ) {
return site_url( '/' . ltrim( (string) $asset_path, '/' ) );
}, 10, 2 );