Hi,
unfortunately in this version there in no simple way to remove empty fields.
Anyway you can do this with custom code by using this filter ‘yith_woocompare_filter_table_fields’ to modify table fields.
add_filter('yith_woocompare_filter_table_fields', 'yith_woocompare_filter_table_fields_custom', 10, 2 );
function yith_woocompare_filter_table_fields_custom($fields, $products){
// your custom code here
return $fields;
}
Regards. 🙂
Не подходит, событие вызывается дважды и второй раз без продуктов
Not suitable, the event is called twice and a second time without products
add_filter('yith_woocompare_filter_table_fields', 'yith_woocompare_filter_table_fields_custom', 10, 2 );
function yith_woocompare_filter_table_fields_custom($fields, $products){
$newFields = array();
if (!empty($products)) {
foreach ($products as $product_id) {
foreach ($fields as $name=>$title) {
if ( stripos($name, 'pa_') === 0 ) {
$terms = get_the_terms($product_id, $name);
if( $terms && !is_wp_error($terms) ) {
$newFields[$name] = $title;
}
} else {
$newFields[$name] = $title;
}
}
}
$fields = $newFields;
}
return $fields;
}
Вот такой костыль получился
Here is such a crutch turned out
add_filter('yith_woocompare_filter_table_fields', 'yith_woocompare_filter_table_fields_custom', 10, 2 );
function yith_woocompare_filter_table_fields_custom($fields, $products){
$newFields = array();
if (empty($products)) {
$woocompare = new YITH_Woocompare_Frontend;
$woocompare->populate_products_list();
$products = $woocompare->products_list;
}
if (!empty($products)) {
foreach ($products as $product_id) {
foreach ($fields as $name=>$title) {
if ( stripos($name, 'pa_') === 0 ) {
$terms = get_the_terms($product_id, $name);
if( $terms && !is_wp_error($terms) ) {
$newFields[$name] = $title;
}
} else {
$newFields[$name] = $title;
}
}
}
$fields = $newFields;
}
return $fields;
}