Hi,
I was wondering if you could help. I may be using the wcv_save_product hook incorrectly… I have registered a custom taxonomy for the product post type, named ‘product_gender’. I have managed to successfully display this in the Pro dashboard product edit page beneath the category selection by calling this custom function from the product-edit.php template:
function prefix_form_gender( $object_id ) {
WCVendors_Pro_Form_helper::select2( array(
‘post_id’ => $object_id,
‘id’ => ‘product_gender[]’,
‘class’ => ‘select2’,
‘label’ => __(‘Gender’, ‘jotu’),
‘show_option_none’ => __(‘Select Gender’, ‘jotu’),
‘taxonomy’ => ‘product_gender’,
‘capabilities’ => ‘manage_product’,
‘taxonomy_args’ => array(
‘hide_empty’ => 0,
)
)
);
}
http://pastebin.com/kafM3YSc
All working fine up to this point. I am able to save the selection of the custom taxonomy when editing an already existing product. I have accomplished this with the below:
add_action( ‘init’, ‘process_tax_save’ );
function process_tax_save() {
if( isset( $_POST[‘product_gender’] ) && isset( $_POST[‘post_id’] ) ) {
$term = $_POST[ ‘product_gender’ ];
$id = (int) $_POST[‘post_id’];
wp_set_object_terms( $id, (int)$term[0], ‘product_gender’ );
}
}
http://pastebin.com/5wTLnVM2
My issue seems to be when creating a brand new product. When creating a new product, I seem unable to save the custom taxonomy. I am using the wcv_save_product hook for this, which as I understand, should run on post save, correct? Below is my code so far for the addition of new products:
function save_caracteristica( $post_ID ){
$term = $_POST[ ‘product_gender’ ];
wp_set_object_terms( (int) $post_ID, (int)$term[0], ‘product_gender’ );
}
add_action( ‘wcv_save_product’, ‘save_caracteristica’, 10, 1 );
http://pastebin.com/5xP38QWb
I have tried countless variations of this. I have tried using te ‘save_posts’ hook, as well as modifying the priority. After spending a good number of hours on this, searching through the forums etc. I figured you may be able to point me in the right direction? I am thinking I may need to use a different hook, perhaps I am using wcv_save_product incorrectly?
Please note, this website is being developed locally.
Thanks,
James.