Hi, thanks for this, I’m using an older version of WCMP just for now but I recognised the code from some tabs I’ve added successfully, thanks for the pointer.
So I’ve added the tab, but for this tab, I don’t seem to be saving the data successfully, I would expect to hit save, and then see my selections from the multi-select box showing there still, present in the dashboard form as I do with the other tabs I’ve added (one of the other tabs I’ve added already is for ‘from and to’ dates, and they remain selected after saving, and the other tab is for an image upload, which also remains present after saving.
Here is my code, – for the tab content, using PODS I’ve created the multi-select form. I have created a relationship field whats_on https://docs.pods.io/fields/relationship/ for products (or tickets in my case), to create a relationship between products/tickets and ‘users’ – so what you’re picking here as a vendor in the dashboard via field whats_on , are other users.
The code below in the content tab creates the front end form for my user. (As per their quick guide here: https://docs.pods.io/code/pods/form/).
The form seems to work fine, the vendor selects their user, but then the data doesn’t appear to save at all. Can you see my problem in the code?
Kind thanks
/**
* Add Custom Tab
* @Version 3.3.0
*/
function add_custom_product_data_tabs_3( $tabs ) {
$tabs['more'] = array(
'label' => __( 'More Stuff...', 'more-stuff' ),
'target' => 'see-more',
'class' => array(),
'priority' => 100,
);
return $tabs;
}
add_filter( 'wcmp_product_data_tabs', 'add_custom_product_data_tabs_3' );
/**
* Add Custom Tab Content
*/
function add_custom_product_data_content_3( $pro_class_obj, $product, $post ) {
//prnt_r($product->get_id());die;
$hh = get_post_meta($product->get_id() , 'whats_on' );
//print_r($hh);
?>
<div role="tabpanel" class="tab-pane fade" id="see-more"> <!-- just make sure tabpanel id should replace with your added tab target -->
<div class="row-padding">
<div class="form-group">
<label class="control-label col-sm-3 col-md-3">More Info:</label>
<div class="col-md-6 col-sm-9">
//start of the pods form
<?php
$pods = pods( 'product' );
$params = array( 'fields_only' => true, 'fields' => array('whats_on') );
echo $pods->form( $params );?>
//end of the pods form
</div>
</div>
</div>
</div>
<?php
}
add_action( 'wcmp_product_tabs_content', 'add_custom_product_data_content_3', 10, 3 );
/**
* Save Custom Tab content
*/
function save_custom_product_data_3( $product, $post_data ) {
if( isset($post_data['post_ID']) && isset($post_data['whats_on'])){
update_post_meta( absint( $post_data['post_ID'] ), 'whats_on', $post_data['whats_on']);
}
}
add_action( 'wcmp_process_product_object', 'save_custom_product_data_3', 10, 2 );