Created
March 13, 2017 15:09
-
-
Save digitalchild/128033d2d41f682acd4387b595d4f607 to your computer and use it in GitHub Desktop.
Custom Taxonomy Support added to Product edit form for WC Vendors Pro
This file contains 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
<?php | |
function form_subjects( $object_id ) { | |
WCVendors_Pro_Form_helper::select2( array( | |
'post_id' => $object_id, | |
'id' => '_wcv_custom_taxonomy_subjects[]', | |
'class' => 'select2', | |
'label' => __('Subjects', 'wcvendors-pro'), | |
'show_option_none' => __('Select Subject(s)', 'wcvendors-pro'), | |
'taxonomy' => 'subjects', | |
'taxonomy_args' => array( | |
'hide_empty' => 0, | |
), | |
'custom_attributes' => array( 'multiple' => 'multiple' ), | |
) | |
); | |
} | |
function save_subjects( $post_id ){ | |
if ( isset( $_POST[ '_wcv_custom_taxonomy_subjects' ] ) && is_array( $_POST[ '_wcv_custom_taxonomy_subjects' ] ) ) { | |
$subjects = array_map( 'intval', $_POST[ '_wcv_custom_taxonomy_subjects' ] ); | |
$subjects = array_unique( $subjects ); | |
wp_set_post_terms( $post_id, $subjects, 'subjects' ); | |
} | |
} | |
add_action( 'wcv_save_product', 'save_subjects' ); | |
?> |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment