Advertisement
Guest User

Untitled

a guest
Dec 7th, 2016
68
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 1.11 KB | None | 0 0
  1. //Must be "Select Field" in "Group Fields (ACF)"
  2.  
  3. add_action( 'edited_term', 'wpse_created_term', 10, 3 );
  4. add_action( 'delete_term', 'wpse_created_term', 10, 3 );
  5. add_action( 'created_term', 'wpse_created_term', 10, 3 );
  6. function wpse_created_term( $term_id, $tt_id, $taxonomy ) {
  7. $postID = 4576;
  8. $attribute_taxonomies = wc_get_attribute_taxonomies();
  9. $post = get_post($postID);
  10. $postContent = unserialize($post->post_content);
  11. $choices = $postContent['choices'];
  12. $attribute_taxonomies = arrayCastRecursive($attribute_taxonomies);
  13. $newAttributes = array();
  14. foreach($attribute_taxonomies as $attribute_taxonomie)
  15. {
  16. $isExist = false;
  17. foreach ($choices as $key => $choice) {
  18. if($attribute_taxonomie['attribute_name'] == $key)
  19. {
  20. $isExist = true;
  21. $newAttributes[$key] = $attribute_taxonomie['attribute_label'];
  22. break;
  23. }
  24. }
  25. if(!$isExist)
  26. {
  27. $newAttributes[$attribute_taxonomie['attribute_name']] = $attribute_taxonomie['attribute_label'];
  28. }
  29. }
  30. $postContent['choices'] = $newAttributes;
  31. $my_post = array( 'ID' => $postID, 'post_content' => serialize($postContent), );
  32. wp_update_post( $my_post );
  33. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement