skip to Main Content

I am trying to replace billing country class from "form-row-wide" to "form-row-first" in both checkout and in My account page but it’s not working.

here is the code I am using

/*replace country class form-row-wide to form-row-first*/
add_filter( 'woocommerce_default_address_fields' , 'country_class_change', 9999 );

function country_class_change( $fields ) {

$fields['billing']['billing_country']['class'][0] = 'my-field-class form-row-first';

return $fields;
}

I used earlier the filter "woocommerce_checkout_fields" but that only worked in the checkout not in My Account page. How to do for both. whats wrong with the code?

2

Answers


  1. Chosen as BEST ANSWER

    I was able to do it with below code

    // change country class
    add_filter( 'woocommerce_default_address_fields' , 'country_class_change' );
    
    function country_class_change( $address_fields ) {
    
        // change country class
        $address_fields['country']['class'] = array('my-field-class form-row-first');
    
        return $address_fields;
    }
    

  2. You’ll need to change the Woocommerce template structure files. The form-row-wide class appears in a number of Woocommerce files. Simply change the markup to add any classes in your Woocommerce custom theme i.e

    woocommerce/auth/form-login.php
    woocommerce/cart/shipping-calculator.php
    woocommerce/checkout/form-billing.php
    woocommerce/myaccount/form-edit-account.php
    woocommerce/myaccount/form-login.php

    Login or Signup to reply.
Please signup or login to give your own answer.
Back To Top
Search