/** * Add extra checkout fields */ add_filter('woocommerce_checkout_fields', 'cc_add_extra_checkout_fields'); function cc_add_extra_checkout_fields($fields) { $fields['extra_fields'] = array( 'student_name' => array( 'type' => 'text', 'required' => true, 'label' => __('Student first and last name'), 'placeholder' => '', 'class' => array('student-name') ), 'student_year' => array( 'type' => 'text', 'required' => true, 'label' => __('Year'), 'placeholder' => '', 'class' => array('student-year') ), ); return $fields; } // display the extra field on the checkout form add_action('woocommerce_checkout_after_customer_details' ,'cc_extra_checkout_fields'); function cc_extra_checkout_fields(){ $checkout = WC()->checkout(); ?> checkout_fields['extra_fields'] as $key => $field ) : ?> get_value( $key ) ); ?> '.__('Student name').': ' . get_post_meta( $order->get_id(), 'student_name', true ) . '
'; echo ''.__('Student year').': ' . get_post_meta( $order->get_id(), 'student_year', true ) . '
'; } /** * Add a custom field (in an order) to the emails */ add_filter('woocommerce_email_order_meta_fields', 'cc_email_order_meta_fields', 10, 3); function cc_email_order_meta_fields($fields, $sent_to_admin, $order) { $fields['student_name'] = array( 'label' => __('Student name'), 'value' => get_post_meta($order->get_id(), 'student_name', true), ); $fields['student_year'] = array( 'label' => __('Student year'), 'value' => get_post_meta($order->get_id(), 'student_year', true), ); return $fields; }