In my woocommerce product page I am trying to add a custom input field so that customers can enter a value in the quantity field that will be carried through the checkout process.
I found some documentation on the Woocommerce site about hooks/actions http://docs.woothemes.com/document/tutorial-customising-checkout-fields-using-actions-and-filters/.
I have added the code below to my functions.php file and at the very least it should display an input field on the product field but it only displays the h2 value.
<?php
/**
* Add the field to the product page
*/
add_action( 'woocommerce_before_add_to_cart_button', 'custom_quantity' );
function custom_quantity( $product ) {
echo '<div id="my_custom_checkout_field"><h2>' . __('My Field') . '</h2>';
woocommerce_form_field( 'my_field_name', array(
'type' => 'text',
'class' => array('my-field-class form-row-wide'),
'label' => __('Fill in this field'),
'placeholder' => __('Enter something'),
), $product->get_value( 'my_field_name' ));
echo '</div>';
}
?>
Can anyone help as to why this is happening? Is there a fault in my code. I am new to woocommerce and trying to figure this out.