Title: Empty fields
Last modified: June 19, 2017

---

# Empty fields

 *  [webinstruktor](https://wordpress.org/support/users/webinstruktor/)
 * (@webinstruktor)
 * [8 years, 9 months ago](https://wordpress.org/support/topic/empty-fields-3/)
 * How to remove empty fields in comparison, not removing attributes?
 * [https://s.mail.ru/Gk3f/fnBGdpEcX](https://s.mail.ru/Gk3f/fnBGdpEcX)

Viewing 3 replies - 1 through 3 (of 3 total)

 *  Plugin Author [YITHEMES](https://wordpress.org/support/users/yithemes/)
 * (@yithemes)
 * [8 years, 9 months ago](https://wordpress.org/support/topic/empty-fields-3/#post-9291232)
 * 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. 🙂
 *  [AlexeyS_AS](https://wordpress.org/support/users/alexeys_as/)
 * (@alexeys_as)
 * [8 years, 9 months ago](https://wordpress.org/support/topic/empty-fields-3/#post-9294526)
 * Не подходит, событие вызывается дважды и второй раз без продуктов
    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;
       }
       ```
   
 *  [AlexeyS_AS](https://wordpress.org/support/users/alexeys_as/)
 * (@alexeys_as)
 * [8 years, 9 months ago](https://wordpress.org/support/topic/empty-fields-3/#post-9295032)
 * Вот такой костыль получился
    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;
       }
       ```
   

Viewing 3 replies - 1 through 3 (of 3 total)

The topic ‘Empty fields’ is closed to new replies.

 * ![](https://ps.w.org/yith-woocommerce-compare/assets/icon.svg?rev=3042935)
 * [YITH WooCommerce Compare](https://wordpress.org/plugins/yith-woocommerce-compare/)
 * [Frequently Asked Questions](https://wordpress.org/plugins/yith-woocommerce-compare/#faq)
 * [Support Threads](https://wordpress.org/support/plugin/yith-woocommerce-compare/)
 * [Active Topics](https://wordpress.org/support/plugin/yith-woocommerce-compare/active/)
 * [Unresolved Topics](https://wordpress.org/support/plugin/yith-woocommerce-compare/unresolved/)
 * [Reviews](https://wordpress.org/support/plugin/yith-woocommerce-compare/reviews/)

## Tags

 * [Empty Fields](https://wordpress.org/support/topic-tag/empty-fields/)

 * 3 replies
 * 3 participants
 * Last reply from: [AlexeyS_AS](https://wordpress.org/support/users/alexeys_as/)
 * Last activity: [8 years, 9 months ago](https://wordpress.org/support/topic/empty-fields-3/#post-9295032)
 * Status: not resolved