WordPress.org

Support

Support » Plugins and Hacks » WooCommerce » Checkout field next to each other

Checkout field next to each other

Viewing 3 replies - 1 through 3 (of 3 total)
  • indira14

    @indira14

    I found that I should add a row class to the postcode and city to get this done.

    I have this code:

    function custom_override_checkout_fields( $fields ) {

    $fields[‘city’] = array(
    ‘label’ => __(‘Town / City’, ‘woocommerce’),
    ‘placeholder’ => _x(‘Town / City’, ‘woocommerce’),
    ‘required’ => true,
    ‘class’ => array(‘form-row-first’)
    ),

    $fields[‘postcode’] = array(
    ‘label’ => __(‘Postcode / Zip’, ‘woocommerce’),
    ‘placeholder’ => _x(‘Postcode / Zip’, ‘woocommerce’),
    ‘required’ => true,
    ‘class’ => array(‘form-row-last’);

    return $fields;

    }

    I’ve put this in my functions.php but the site breaks. How do I get this working properly?

    I also have the following code just above it

    add_filter( ‘woocommerce_checkout_fields’ , ‘custom_override_checkout_fields’ );

    function custom_override_checkout_fields( $fields ) {

    unset($fields[‘billing’][‘billing_address_2’]);

    unset($fields[‘billing’][‘billing_company’]);

    unset($fields[‘shipping’][‘shipping_address_2’]);

    unset($fields[‘shipping’][‘shipping_company’]);

    }

    indira14

    @indira14

    I also found this code, I think this is actually what I should be using:

    // Hook in
    add_filter( 'woocommerce_default_address_fields' , 'custom_override_default_address_fields' );
    
    // Our hooked in function - $address_fields is passed via the filter!
    function custom_override_default_address_fields( $address_fields ) {
         $address_fields['address_1']['required'] = false;
    
         return $address_fields;
    }

    This is what I made of it, but it is not working. Can somebody correct me here?

    // Hook in
    add_filter( 'woocommerce_default_address_fields' , 'custom_override_default_address_fields' );
    
    // Our hooked in function - $address_fields is passed via the filter!
    function custom_override_default_address_fields( $address_fields ) {
         $address_fields['city']['class'] = array('form-row-first');
         $address_fields['postcode']['class'] = array('form-row-last');
    
         return $address_fields;
    }

    [Moderator Note: Please post code & markup between backticks or use the code button. Your posted code may now have been permanently damaged by the forum’s parser.]

    i have exactly the same problem. after reading the documentation i came up with the same code like you… but it doesn’t work

    i also tried it with this code:

    function custom_override_default_address_fields( $address_fields ) {
          $address_fields['postcode']  = array(
          'label'          => __('Postcode', 'woothemes'),
          'placeholder'    => __('Postcode', 'woothemes'),
          'required'       => false,
          'class'          => array('form-row-first'),
          'label_class'    => array('testing')
       	);  
    
    	 return $address_fields;
    }

    it seems that everything works fine (like setting required to false, change the label name, label class, placeholder…) but NOT the class!?

    maybe someone knows what could be wrong, thanks!

Viewing 3 replies - 1 through 3 (of 3 total)
  • The topic ‘Checkout field next to each other’ is closed to new replies.
Skip to toolbar