I have worked on your issue and found a solution after some Google.
Note: Add the below mentioned code to theme’s functions.php
or any plugin’s file.
Code:
This filter function will add a custom tab to the Products Data
metabox
<?php
add_filter( 'woocommerce_product_data_tabs', 'add_my_custom_product_data_tab' , 99 , 1 );
function add_my_custom_product_data_tab( $product_data_tabs ) {
$product_data_tabs['my-custom-tab'] = array(
'label' => __( 'My Custom Tab', 'my_text_domain' ),
'target' => 'my_custom_product_data',
);
return $product_data_tabs;
}
This action will add custom fields to the added custom tabs under Products Data
metabox
add_action( 'woocommerce_product_data_panels', 'add_my_custom_product_data_fields' );
function add_my_custom_product_data_fields() {
global $woocommerce, $post;
?>
<!-- id below must match target registered in above add_my_custom_product_data_tab function -->
<div id="my_custom_product_data" class="panel woocommerce_options_panel">
<?php
woocommerce_wp_checkbox( array(
'id' => '_my_custom_field',
'wrapper_class' => 'show_if_simple',
'label' => __( 'My Custom Field Label', 'my_text_domain' ),
'description' => __( 'My Custom Field Description', 'my_text_domain' ),
'default' => '0',
'desc_tip' => false,
) );
?>
</div>
<?php
}
?>
Save custom fields data of products tab:
add_action( 'woocommerce_process_product_meta', 'woocommerce_process_product_meta_fields_save' );
function woocommerce_process_product_meta_fields_save( $post_id ){
// This is the case to save custom field data of checkbox. You have to do it as per your custom fields
$woo_checkbox = isset( $_POST['_my_custom_field'] ) ? 'yes' : 'no';
update_post_meta( $post_id, '_my_custom_field', $woo_checkbox );
}
Hope this helps!