Skip to content

Instantly share code, notes, and snippets.

@igorbenic
Created June 4, 2021 12:44
Show Gist options
  • Save igorbenic/219637350cd593f8e12345c9918466b9 to your computer and use it in GitHub Desktop.
Save igorbenic/219637350cd593f8e12345c9918466b9 to your computer and use it in GitHub Desktop.
Ignore Product Meta data from WooCommerce Importer
<?php
add_filter( 'woocommerce_product_import_process_item_data', 'wc_ignore_meta_in_import_if_non_value' );
/**
* Ignore the meta if value is empty
*
* @param array $data Data.
*
* @return array
*/
function wc_ignore_meta_in_import_if_non_value( $data ) {
$ignore_with_key = array( 'meta_key_1', 'meta_key_2' );
if ( isset( $data['meta_data'] ) ) {
foreach ( $data['meta_data'] as $index => $meta ) {
// Don't do anything if meta key is not in this array.
if ( ! in_array( $meta['key'], $ignore_with_key, true ) {
continue;
}
if ( null === $meta['value'] || '' === $meta['value'] ) {
unset( $data['meta_data'][ $index ];
}
}
}
return $data;
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment