Hey Abundance-
I've added this coding to my functions.php file:
/**
* Add the field to the checkout
**/
add_action('woocommerce_after_order_notes', 'my_custom_checkout_field');
function my_custom_checkout_field( $checkout ) {
echo '<div id="my_custom_checkout_field"><h3>'.__('Delivery Date').'</h3>';
woocommerce_form_field( 'delivery_date_name', array(
'type' => 'text', 'class' => array('delivery-date-class form-row-wide'),
'label' => __('Eg. Tues, July 22.'),
'placeholder' => __('Date of Delivery'),
), $checkout->get_value( 'my_field_name' ));
echo '</div>';
}
/**
* Process the checkout
**/add_action('woocommerce_checkout_process', 'my_custom_checkout_field_process');
function my_custom_checkout_field_process() {
global $woocommerce;
// Check if set, if its not set add an error.
if (!$_POST['delivery_date_name'])
$woocommerce->add_error( __('Please enter delivry date.') );
}
/** * Update the order meta with field value
**/
add_action('woocommerce_checkout_update_order_meta', 'my_custom_checkout_field_update_order_meta');
function my_custom_checkout_field_update_order_meta( $order_id ) {
if ($_POST['delivery_date_name']) update_post_meta( $order_id, 'Delivery Date', esc_attr($_POST['delivery_date_name']));
}
WORKS GREAT! I can see my new custom field reads Delivery Date. The problem happens when I want to add another custom field to read Recipeint Phone. I add the following code right underneath the above:
/**
* Add the field to the checkout
**/
add_action('woocommerce_after_order_notes', 'my_custom_checkout_field');
function my_custom_checkout_field( $checkout ) {
echo '<div id="my_custom_checkout_field"><h3>'.__('Recipeint Phone').'</h3>';
woocommerce_form_field( 'recipient_phone_name', array(
'type' => 'text', 'class' => array('recipient-phone-class form-row-wide'),
'label' => __('Home & or Cell'),
'placeholder' => __('Both numbers would be great!'),
), $checkout->get_value( 'recipeint_phone_name' ));
echo '</div>';
}
/**
* Process the checkout
**/add_action('woocommerce_checkout_process', 'my_custom_checkout_field_process');
function my_custom_checkout_field_process() {
global $woocommerce;
// Check if set, if its not set add an error.
if (!$_POST['recipeint_phone_name'])
$woocommerce->add_error( __('Please enter phone number.') );
}
/** * Update the order meta with field value
**/
add_action('woocommerce_checkout_update_order_meta', 'my_custom_checkout_field_update_order_meta');
function my_custom_checkout_field_update_order_meta( $order_id ) {
if ($_POST['delivery_date_name']) update_post_meta( $order_id, 'Recipient Phone', esc_attr($_POST['my_field_name']));
}
My site just goes blank. Can someone tell me if there's something wrong with the second part of this coding?
Minnoe














