• Resolved meharpro

    (@meharpro)


    i want to add an additional field in the checkout form. Field name would be ” Enter Your Pickup Address “. Please provide me code and guide me how i can add that code in my theme. Thanks!!

    The page I need help with: [log in to see the link]

Viewing 1 replies (of 1 total)
  • Plugin Author bookingalgorithms

    (@bookingalgorithms)

    Hello,

    You need to place in the child theme functions.php the custom code like in this example (edit it as you need):

    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. Use it only if you need to make field required
    */
    function customtheme_babe_checkout_field_required($required_tag, $field_name){
       if ($field_name === 'new_field'){
          $required_tag = 'required="required"';
       }
       return $required_tag;
    }
    ///////////////////
    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;
    }
    /////////////////////
    


    Best Regards,
    Booking Algorithms team

Viewing 1 replies (of 1 total)
  • The topic ‘add custom field in checkout field’ is closed to new replies.