Skip to content

Instantly share code, notes, and snippets.

@cmdmcs
Created November 6, 2018 20:35
Show Gist options
  • Save cmdmcs/c6e47679a2921a63ade38ab59e3f0e77 to your computer and use it in GitHub Desktop.
Save cmdmcs/c6e47679a2921a63ade38ab59e3f0e77 to your computer and use it in GitHub Desktop.
add_filter('wp_all_import_set_post_terms', 'wpai_wp_all_import_set_post_terms', 10, 4);
function wpai_wp_all_import_set_post_terms($assign_terms, $tx_name, $pid, $import_id) {
if ($tx_name == 'product_cat'){
$post = get_post($pid);
if ($post->post_type == 'product_variation') {
$parentID = $post->post_parent;
$term_ids = wp_get_object_terms($parentID, $tx_name, array( 'fields' => 'ids' ));
if (!empty($assign_terms)) {
foreach ($assign_terms as $term_id) {
if (!in_array($term_id, $term_ids)) {
$term_ids[] = $term_id;
}
}
}
wp_set_object_terms($parentID, $term_ids, $tx_name);
}
}
return $assign_taxes;
}
@Programmer095
Copy link

Looks like there's a typo where 'return $assign_taxes;' should actually be 'return $assign_terms;'.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment