The issue was that you should have changed product_noncename
to goal_info_meta_box_nonce
. I’ve also made a few other changes, commenting out the old lines for comparison, which should avoid any further errors (including the undefined index).
// verify nonce
// if ( ! isset( $_POST['product_noncename'] ) || ! wp_verify_nonce( $_POST['goal_info_meta_box_nonce'], basename( __file__ ) ) ) {
if ( ! isset( $_POST['goal_info_meta_box_nonce'] ) || ! wp_verify_nonce( $_POST['goal_info_meta_box_nonce'], basename( __file__ ) ) ) {
return $post_id;
}
...
// loop through fields and save the data
foreach ( $goal_info_meta_fields as $field ) {
// if ( $field['type'] == 'tax_select' )
if ( $field['type'] == 'tax_select' || ! isset( $_POST[ $field['id'] ] ) )
continue;
$old = get_post_meta( $post_id, $field['id'], true );
$new = $_POST[ $field['id'] ];
// if ( isset( $new ) && ! empty( $new ) && ( $new != $old ) ) {
if ( ! empty( $new ) && $new != $old ) {
update_post_meta( $post_id, $field['id'], $new );
} elseif ( '' == $new && $old ) {
delete_post_meta( $post_id, $field['id'], $old );
}
}