Skip to content

Instantly share code, notes, and snippets.

@robdvr
Created November 13, 2013 16:12
Show Gist options
  • Star 5 You must be signed in to star a gist
  • Fork 4 You must be signed in to fork a gist
  • Save robdvr/7451695 to your computer and use it in GitHub Desktop.
Save robdvr/7451695 to your computer and use it in GitHub Desktop.
Adding Bootstrap Forms to WooCommerce
add_filter('woocommerce_billing_fields', 'custom_woocommerce_billing_fields');
function custom_woocommerce_billing_fields( $fields ) {
$fields['billing_address_1']['class'] = array( 'form-group' );
$fields['billing_address_1']['input_class'] = array( 'form-control' );
return $fields;
}
@PascalPixel
Copy link

how do i do this to all fields?

@robdvr
Copy link
Author

robdvr commented Oct 30, 2014

@Superpencil, I just saw this comment. Where you able to figure this out? I can find the solution for you.

@purplenimbus
Copy link

perhaps you could share the bootstrap fix for all fields

@ajithrn
Copy link

ajithrn commented May 19, 2016

try this

add_filter('woocommerce_form_field_args',  'wc_form_field_args',10,3);
  function wc_form_field_args($args, $key, $value) {
  $args['input_class'] = array( 'form-control' );
  return $args;
}

@EranSch
Copy link

EranSch commented Oct 9, 2017

Adding this for ages– builds upon the previous examples, hitting every input and adding form-group to the container, and form-control to the input. It also appends to the class arrays instead of overwrites, this might help avoid plugin conflicts.

add_filter('woocommerce_form_field_args', function ($args, $key, $value) {
    $args['input_class'][] = 'form-control';
    $args['class'][] = 'form-group';
    return $args;
}, 10, 3);

@kirsty-gasston
Copy link

This is great, but only applies to the actual checkout - is there a straightforward way at all of doing this sitewide?

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment