I added successfully a Metabox with a multi checkbox field that is displayed on admin single order pages and works perfectly.
I am using Multi checkbox fields in Woocommerce backend answer code for that multi checkbox.
// Adding Meta container admin shop_order pages
add_action( 'add_meta_boxes', 'em_add_meta_boxes' );
if ( ! function_exists( 'em_add_meta_boxes' ) )
{
function em_add_meta_boxes()
{
add_meta_box( 'em_other_fields', __('Employee Extra Actions','woocommerce'), 'em_add_other_fields_for_order_empl', 'shop_order', 'side', 'core' );
}
}
// Adding Meta field in the meta container admin shop_order pages
if ( ! function_exists( 'em_add_other_fields_for_order_empl' ) )
{
function em_add_other_fields_for_order_empl()
{
global $post;
echo '<div class="options_group">';
woocommerce_wp_multi_checkbox( array(
'id' => 'employee_actions12',
'name' => 'employee_actions12[]',
'label' => __('Levels', 'woocommerce'),
'options' => array(
'tee' => __( 'MBO', 'woocommerce' ),
'saa' => __( 'HBO', 'woocommerce' ),
'tee1' => __( 'WO', 'woocommerce' ),
)
) );
echo '</div>';
}
}
Final part of code is to save at database, Here is it:
add_action( 'save_post', 'save_product_options_custom_fields32', 30, 1 );
function save_product_options_custom_fields32( $post_id ){
if( isset( $_POST['employee_actions12'] ) ){
$post_data = $_POST['employee_actions12'];
// Multi data sanitization
$sanitize_data = array();
if( is_array($post_data) && sizeof($post_data) > 0 ){
foreach( $post_data as $value ){
$sanitize_data[] = esc_attr( $value );
}
}
update_post_meta( $post_id, 'employee_actions12', $sanitize_data );
}
}
I know code works for product pages with action: 'woocommerce_product_process_meta'
So, i need help for saving at db, an fixing error notice for array (i think this can happen if we select default value).