Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- //Must be "Select Field" in "Group Fields (ACF)"
- add_action( 'edited_term', 'wpse_created_term', 10, 3 );
- add_action( 'delete_term', 'wpse_created_term', 10, 3 );
- add_action( 'created_term', 'wpse_created_term', 10, 3 );
- function wpse_created_term( $term_id, $tt_id, $taxonomy ) {
- $postID = 4576;
- $attribute_taxonomies = wc_get_attribute_taxonomies();
- $post = get_post($postID);
- $postContent = unserialize($post->post_content);
- $choices = $postContent['choices'];
- $attribute_taxonomies = arrayCastRecursive($attribute_taxonomies);
- $newAttributes = array();
- foreach($attribute_taxonomies as $attribute_taxonomie)
- {
- $isExist = false;
- foreach ($choices as $key => $choice) {
- if($attribute_taxonomie['attribute_name'] == $key)
- {
- $isExist = true;
- $newAttributes[$key] = $attribute_taxonomie['attribute_label'];
- break;
- }
- }
- if(!$isExist)
- {
- $newAttributes[$attribute_taxonomie['attribute_name']] = $attribute_taxonomie['attribute_label'];
- }
- }
- $postContent['choices'] = $newAttributes;
- $my_post = array( 'ID' => $postID, 'post_content' => serialize($postContent), );
- wp_update_post( $my_post );
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement