Skip to content

Instantly share code, notes, and snippets.

@digitalchild
Created March 13, 2017 15:09
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save digitalchild/128033d2d41f682acd4387b595d4f607 to your computer and use it in GitHub Desktop.
Save digitalchild/128033d2d41f682acd4387b595d4f607 to your computer and use it in GitHub Desktop.
Custom Taxonomy Support added to Product edit form for WC Vendors Pro
<?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