Skip to content

Instantly share code, notes, and snippets.

@webtoffee-git
Last active June 9, 2025 09:49
Show Gist options
  • Save webtoffee-git/c502817f6f6f72cb20562bb6bc7729a6 to your computer and use it in GitHub Desktop.
Save webtoffee-git/c502817f6f6f72cb20562bb6bc7729a6 to your computer and use it in GitHub Desktop.
Code to import only certain brands - By WebToffee (Product import export basic)
<?php>//Do not copy this line of code
add_filter('wt_iew_importer_do_import_basic', 'filter_products_by_brand', 1, 4);
function filter_products_by_brand($data_arr, $to_process, $step, $selected_template_data) {
// Define allowed brands (normalized to uppercase and trimmed)
$allowed_brands = array_map('strtoupper', array_map('trim', array('Brand1', 'Brand2', 'Brand3')));
foreach ($data_arr as $key => $product) {
if (isset($product['meta_mapping_fields']['taxonomies']['tax:product_brand'])) {
$raw_brand = $product['meta_mapping_fields']['taxonomies']['tax:product_brand'];
$normalized_brand = strtoupper(trim($raw_brand));
if (!in_array($normalized_brand, $allowed_brands)) {
unset($data_arr[$key]);
}
} else {
// No brand found — exclude the product
unset($data_arr[$key]);
}
}
return $data_arr;
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment