1

I am working on E-commerce functions where i require to Add custom fieldset as Profile Fields the fields in it are as billing

Below are the Fields that is needed in My Check out and signup form

profile_first_name
profile_last_name
profile_company
profile_address_1
profile_address_2
profile_city
profile_postcode
profile_country
profile_state
profile_email
profile_phone

Can you please guide me on this issue how can set add all above fields in my wordpress theme and what Actions or Filters should i use to display in Checkout form

Thanks in Advance

Nikhil

0

The "Customizing checkout fields using actions and filters" page in the WooCommerce Codex might help you.

  • 4
    Answers should be more than links... – kaiser Oct 29 '13 at 16:35
  • HI I have Gone through that Link and tried creating Fields but it limits me to some extent I am thinking to Override the class-wc-checkout.php with my custom file in theme as this was possible after that i can create the get_default_address_fields and get_address_fields methods (That was in class-wc-countries.php) and use these functions on the Checkout form. sadly i cannot Over ride the class-wc-countries.php in my theme otherwise every thing will have been easily done. Do Let Me know your Views on this method NIkhil – Nikhil Joshi Oct 30 '13 at 11:56
4

Very old, but this still come up when searching, so I will add that my article WooCommerce Customize Checkout Fields here is a sample of adding a new checkout field:

// Add a new checkout field
function kia_filter_checkout_fields($fields){
    $fields['extra_fields'] = array(
            'some_field' => array(
                'type' => 'text',
                'required'      => true,
                'label' => __( 'Some field' )
                )
            );

    return $fields;
}
add_filter( 'woocommerce_checkout_fields', 'kia_filter_checkout_fields' );

// display the extra field on the checkout form
function kia_extra_checkout_fields(){ 

    $checkout = WC()->checkout(); ?>

    <div class="extra-fields">
    <h3><?php _e( 'Additional Fields' ); ?></h3>

    <?php foreach ( $checkout->checkout_fields['extra_fields'] as $key => $field ) : ?>

            <?php woocommerce_form_field( $key, $field, $checkout->get_value( $key ) ); ?>

        <?php endforeach; ?>
    </div>

<?php }
add_action( 'woocommerce_checkout_after_customer_details' ,'kia_extra_checkout_fields' );

// save the extra field when checkout is processed
function kia_save_extra_checkout_fields( $order_id, $posted ){
    if( isset( $posted['some_field'] ) ) {
        update_post_meta( $order_id, '_some_field', sanitize_text_field( $posted['some_field'] ) );
    }
}
add_action( 'woocommerce_checkout_update_order_meta', 'kia_save_extra_checkout_fields', 10, 2 );

// display the extra data in the order admin panel
function kia_display_order_data_in_admin( $order ){  ?>
    <div class="order_data_column">
        <h4><?php _e( 'Extra Details', 'woocommerce' ); ?></h4>
        <?php 
            echo '<p><strong>' . __( 'Some field' ) . ':</strong>' . get_post_meta( $order->id, '_some_field', true ) . '</p>'; ?>
    </div>
<?php }
add_action( 'woocommerce_admin_order_data_after_order_details', 'kia_display_order_data_in_admin' );

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.