I'm using Woocommerce and on the single product page I'd like to display some custom form fields in addition to the default "quantity" field.
These form fields are simple: first_name, last_name, email, and phone. I would like to collect this information when the user purchaes the product.
I tried using a plugin first: https://wordpress.org/plugins/woo-extra-product-options/. This allowed me to add the fields but the labels were not displayed correctly so I don't wish to use this one.
Second, the only code examples I've found are for adding custom product fields in the backend and the following code which doesn't output a textfield:
add_action( 'woocommerce_after_single_product_summary', 'add_custom_field', 0 );
function add_custom_field() {
global $post;
echo "<div class='prod-code'>Product Code: ";
$text= get_post_meta('_text_field', $post->ID);
echo "</div>";
return true;
}
How can I add the extra form fields to the single product page?