Skip to content

Instantly share code, notes, and snippets.

@digitalchild
Last active January 25, 2017 21:28
Show Gist options
  • Star 1 You must be signed in to star a gist
  • Fork 2 You must be signed in to fork a gist
  • Save digitalchild/395f22fd79c95b5d8491e7a5275de7f7 to your computer and use it in GitHub Desktop.
Save digitalchild/395f22fd79c95b5d8491e7a5275de7f7 to your computer and use it in GitHub Desktop.
Custom Taxonomy
<?php
// This code goes in your theme's functions.php
function form_caracteristica( $object_id ) {
WCVendors_Pro_Form_helper::select2( array(
'post_id' => $object_id,
'id' => 'wcv_custom_product_caracteristicas[]',
'class' => 'select2',
'label' => __('Caracteristicas', 'wcvendors-pro'),
'show_option_none' => __('Select a caracteristicas', 'wcvendors-pro'),
'taxonomy' => 'caracteristica',
'taxonomy_args' => array(
'hide_empty' => 0,
),
'custom_attributes' => array( 'multiple' => 'multiple' ),
)
);
}
function save_caracteristica( $post_id ){
$term = $_POST[ 'wcv_custom_product_caracteristicas' ];
$terms = implode(',', $term );
wp_set_post_terms( $post_id, $term, 'caracteristica' );
}
add_action( 'wcv_save_product', 'save_caracteristica' );
// Now put the following line in your product-edit.php template override
<?php form_caracteristica( $object_id ); ?>
@goldenprofile
Copy link

goldenprofile commented Jan 25, 2017

Hello digitalchild, i'm trying to add similar code to functions.php and product-edit.php, then add product in frontend dashboard, then save them. After save product don't contain selected value from taxonomy field. Do you have any ideas how solve this issue?

My code

function form_country( $object_id ) { 
 WCVendors_Pro_Form_Helper::select2( array(
			'post_id'			=> $object_id,
			'id'				=> 'wcv_custom_product_country[]',
			'class'				=> 'select2',
			'label'				=> __('Product Country', 'wcvendors-pro'),
			'show_option_none'	=> __('Select country', 'wcvendors-pro'),
			'taxonomy'			=>	'country', 
			'taxonomy_args'		=> array( 
									'hide_empty'	=> 0, 
								), 	
			'custom_attributes'	=> array( 'multiple' => 'multiple' ), 
			)
	); 
}
function save_country( $post_id ){ 
	$term = $_POST[ 'wcv_custom_product_country' ]; 
	$terms = implode(',', $term ); 
	wp_set_post_terms( $post_id, $term, 'country' ); 
}
add_action( 'wcv_save_product', 'save_country' ); 

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment