Created
June 4, 2021 12:44
-
-
Save igorbenic/219637350cd593f8e12345c9918466b9 to your computer and use it in GitHub Desktop.
Ignore Product Meta data from WooCommerce Importer
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
<?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