You are here

Add custom meta box with html and save to db

  /*custom meta box Secondary Form*/
  function custom_meta_box_markup($object) {
  wp_nonce_field(basename(__FILE__), "meta-box-nonce");
    ?>
        <div>
            <?php
                $checkbox_value_one
= get_post_meta($object->ID, "meta-box-checkbox-one", true);
                if(
$checkbox_value_one == "")
                {
                   
?>

                        <input name="meta-box-checkbox-one" type="checkbox" value="true">
                    <?php
               
}
                else if(
$checkbox_value_one == "true")
                {
                   
?>
 
                        <input name="meta-box-checkbox-one" type="checkbox" value="true" checked>
                    <?php
               
}
           
?>

            <label for="meta-box-checkbox-one">Form 1 Completed</label>
        </div>
        <div>
            <?php
                $checkbox_value_two
= get_post_meta($object->ID, "meta-box-checkbox-two", true);
                if(
$checkbox_value_two == "")
                {
                   
?>

                        <input name="meta-box-checkbox-two" type="checkbox" value="true">
                    <?php
               
}
                else if(
$checkbox_value_two == "true")
                {
                   
?>
 
                        <input name="meta-box-checkbox-two" type="checkbox" value="true" checked>
                    <?php
               
}
           
?>

            <label for="meta-box-checkbox-one">Form 2 Completed</label>
        </div>
    <?php
  }
    function add_custom_meta_box()
    {
        add_meta_box("demo-meta-box", "Admin Actions", "custom_meta_box_markup", "shop_order", "side", "high", null);
    }
   add_action("add_meta_boxes", "add_custom_meta_box");  
   function save_custom_meta_box($post_id, $post, $update)
    {
        if (!isset($_POST["meta-box-nonce"]) || !wp_verify_nonce($_POST["meta-box-nonce"], basename(__FILE__)))
            return $post_id;
        if(!current_user_can("edit_post", $post_id))
            return $post_id;
        if(defined("DOING_AUTOSAVE") && DOING_AUTOSAVE)
            return $post_id;
        $slug = "shop_order";
        if($slug != $post->post_type)
            return $post_id;
        $meta_box_checkbox_value_one = "";
        $meta_box_checkbox_value_two = "";
        if(isset($_POST["meta-box-checkbox-one"]))
        {
            $meta_box_checkbox_value_one = $_POST["meta-box-checkbox-one"];
        }
        update_post_meta($post_id, "meta-box-checkbox-one", $meta_box_checkbox_value_one);
        if(isset($_POST["meta-box-checkbox-two"]))
        {
            $meta_box_checkbox_value_two = $_POST["meta-box-checkbox-two"];
        }
        update_post_meta($post_id, "meta-box-checkbox-two", $meta_box_checkbox_value_two);
    }
    add_action("save_post", "save_custom_meta_box", 10, 3);
code type: 
Taken from: 
https://www.sitepoint.com/adding-custom-meta-boxes-to-wordpress/