Bootstrap, the most popular HTML, CSS and JS framework for developing responsive, mobile first projects on the web. Being so popular yet not accepted by many of other Open Source development providers like WooCommerce. Well, there is no way we can complain to them for this, as WooCommerce is providing great plugins to make eCommerce development easy in WordPress.
But we do have to find possible solutions to use Bootstrap if we are using it for responsive website development.
To add ‘form-control‘ Bootstrap class in WooCommerce default checkout form, add below filter to functions.php in your theme.
add_filter( 'woocommerce_form_field_args', 'wc_form_field_args', 10, 3 );
function wc_form_field_args( $args, $key, $value ) {
$args['input_class'][] = 'form-control';
return $args;
}This adds Bootstrap’s form-control class alongside WooCommerce’s own classes instead of replacing them. It applies to every field WooCommerce prints with woocommerce_form_field(), so the address fields in My Account get it too, not only checkout.
View or fork this snippet on GitHub Gist.
Want this checked on your own site? See Exivon Tech’s Website & E-commerce Audit.



2 responses to “Add Bootstrap Class to WooCommerce Checkout Fields”
https://www.dhirenpatel.me/wc-checkout-bootstrap/
On the page it says “add below filter to functions.php…” but there no filter shown below or above.
Hey Alex,
Sorry, the embedded code was lost due to issue with WP plugin which I have used. I have embedded the code again.
Hope it helps.