Adding a new custom shipping field in woocommerce

I’d like to add a new custom billing field in my woocommerce checkout. After adding the following code inside my child theme functions.php, saved it and refreshed the page, I received a blank page. There was no error message. I believe there must be syntax error or something.

add_filter('woocommerce_checkout_fields','custom_override_checkout_fields');
function custom_override_checkout_fields($fields) {
   $fields['shipping']['about_yourself'] = array(
      'label' => __('About yourself', 'woocommerce'),
      'placeholder' => _x('About yourself', 'placeholder', 'woocommerce'),
      'required' => false,
      'class' => array('form-row-wide');
      'clear' => true
   );
   return $fields;
}

I was wondering if anyone could help me out.

Read More

Thank you in advance

Related posts

Leave a Reply

2 comments

  1. The error is in your array field that should be like:

    $fields['shipping']['about_yourself'] = array(
      'label' => __('About yourself', 'woocommerce'),
      'placeholder' => _x('About yourself', 'placeholder', 'woocommerce'),
      'required' => false,
      'class' => array('form-row-wide'), 
      'clear' => true
    );
    

    NOTE: During development process to enable the error_reporting() and set WP_DEBUG true. This is how you enable it during WordPress development in wp-config.php file

    define('WP_DEBUG', true);
    define('WP_DEBUG_LOG', true);
    define('WP_DEBUG_DISPLAY', false);
    @ini_set('display_errors', 0);
    
  2. You have added ; instead of , in 'class' => array('form-row-wide');

    So your code would be :

    add_filter('woocommerce_checkout_fields','custom_override_checkout_fields');
        function custom_override_checkout_fields($fields) {
           $fields['shipping']['about_yourself'] = array(
              'label' => __('About yourself', 'woocommerce'),
              'placeholder' => _x('About yourself', 'placeholder', 'woocommerce'),
              'required' => false,
              'class' => array('form-row-wide'),
              'clear' => true
           );
           return $fields;
    }