Add custom fields to the booking object

BA Book Everything uses CMB2 plugin to create metaboxes with custom fields. So you can follow CMB2 documentation to easily create own metaboxes and custom fields.
You can also use one of the plugin hooks to add new custom field to an existing metabox, as shown below. Then you can use function get_post_meta($post_id, 'new_field_slug', 1) to show new field in your booking object post template.

add_action('cmb2_booking_obj_after_av_dates', 'wptheme_cmb2_booking_obj_after_av_dates', 10);
/**
 * Add custom field to booking object post metabox
 *
 * @param object CMB2 object
 */
function wptheme_cmb2_booking_obj_after_av_dates( $cmb ) {

    $cmb->add_field( array(
    'name'       => __( 'New field title' ),
    'desc'       => __( 'field description (optional)' ),
    'id'         => 'new_field_slug',
    'type'       => 'text',
    ) );
    
   return;
}

add_filter( 'babe_post_content_after_calendar', 'wptheme_babe_post_content_after_calendar', 10, 4);
/**
 * Show new field in booking object post template after calendar section
 *
 * @param string - additional content, empty by default
 * @param string - post content
 * @param int - post ID
 * @param array - BABE post array
 * @return string
 */
function wptheme_babe_post_content_after_calendar( $additional_content, $post_content, $post_id, $post ) {

   $additional_content = '<div><label>'.__( 'New field title:' ).'</label> '. wp_kses_post( get_post_meta($post_id, 'new_field_slug', 1) ).'</div>';
    
   return $additional_content;
}

Cookies

This site uses cookies to enhance your user experience and analyse traffic to improve this website. By clicking any link on this page you are giving your consent for us to set cookies. Please, see our Privacy Policy for additional information.
Scroll to top