Created
November 6, 2018 20:35
-
-
Save cmdmcs/c6e47679a2921a63ade38ab59e3f0e77 to your computer and use it in GitHub Desktop.
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
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; | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Looks like there's a typo where 'return $assign_taxes;' should actually be 'return $assign_terms;'.