Hello,
There are several hooks that you can use in a child theme for your tasks. As a starting solution, this can be:
add_filter('babe_checkout_args', 'customtheme_babe_checkout_args', 10, 2);
/**
* Add checkout fields
*/
function customtheme_babe_checkout_args( $args_meta, $args ) {
$args_meta['new_field'] = isset($args['meta']['new_field']) ? $args['meta']['new_field'] : '';
return $args_meta;
}
////////
add_filter('babe_checkout_field_label', 'customtheme_babe_checkout_field_label', 10, 2);
/**
* Add checkout field title
*/
function customtheme_babe_checkout_field_label( $field_title, $field_name ) {
if (field_name === 'new_field'){
$field_title = __('Field Title', 'textdomain');
}
return $field_title;
}
////////
add_filter('babe_checkout_field_required', 'customtheme_babe_checkout_field_required', 10, 2);
/**
* Required tag for checkout field
*/
function customtheme_babe_checkout_field_required($required_tag, $field_name){
if (field_name === 'new_field'){
$required_tag = 'required="required"';
}
return $required_tag;
}
—
Best Regards,
Booking Algorithms team
I have tried, it works, thanks.
There was a missing $ on field_name
How can I include the new field in the notification email received after the order?
It’s not added automatically.
Thanks.
Hello,
You are right. You need one more hook to save custom field and add it to notification email:
add_filter('babe_sanitize_checkout_vars', 'customtheme_sanitize_checkout_vars', 10, 2);
/**
* Add fields to sanitize checkout vars method
*/
function customtheme_sanitize_checkout_vars( $output, $arr ) {
$output['new_field'] = isset($arr['new_field']) ? sanitize_text_field($arr['new_field']) : '';
return $output;
}
You are welcome!
—
Best Regards,
Booking Algorithms team