WordPress.org

Ready to get started?Download WordPress

Forums

WooCommerce - excelling eCommerce
Checkout field next to each other (4 posts)

  1. indira14
    Member
    Posted 8 months ago #

    I would like to have the checkout fields Postcode and City to appear next to each other, the same way that first name and last name do. How can I achieve this?

    http://wordpress.org/plugins/woocommerce/

  2. indira14
    Member
    Posted 8 months ago #

    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']);

    }

  3. indira14
    Member
    Posted 8 months ago #

    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.]

  4. tobyy
    Member
    Posted 3 weeks ago #

    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!

Reply

You must log in to post.

About this Plugin

About this Topic