Custom Override – Cannot modify header information
-
Followed these instructions (https://wcdocs.woothemes.com/snippets/tutorial-customising-checkout-fields-using-actions-and-filters/#section-4) for adding a new field to the checkout form, and changing the text in the Order Notes box.
Everything worked great (thanks for the tut, btw!), but I’m getting the below error, when changing any setting in the general settings tab of woocommerce plugin. The error loads in the admin section of WP, not the website.
“Warning: Cannot modify header information – headers already sent by (output started at /home/content/53/10228053/html/wp-content/themes/responsive-child-theme/functions.php:16) in /home/content/53/10228053/html/wp-includes/pluggable.php on line 876”
I’m using Responsive Child theme and added everything to the function.php in this fashion.
(this is the start of line 16)
<?php // Hook in add_filter( 'woocommerce_checkout_fields' , 'custom_override_checkout_fields' ); // Our hooked in function - $fields is passed via the filter! function custom_override_checkout_fields( $fields ) { $fields['order']['order_comments']['placeholder'] = 'Send a note to the Bride and Groom!'; ; return $fields; } ?> <?php /** * 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>'.__(' Couple').'</h3>'; woocommerce_form_field( 'my_field_name', array( 'type' => 'text', 'class' => array('my-field-class form-row-wide'), 'label' => __(''), 'placeholder' => __('Groom Last Name Bride Last Name'), ), $checkout->get_value( 'my_field_name' )); echo '</div>'; } ?> <?php /** * 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['my_field_name']) $woocommerce->add_error( __('Please enter the last names into the Bride and Groom field Below.') ); } ?> <?php /** * 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['my_field_name']) update_post_meta( $order_id, 'My Field', esc_attr($_POST['my_field_name'])); } ?>
This is line 876 of pluggable.php
header("Location: $location", true, $status);
Any advice for this situation?
Thank you!
- The topic ‘Custom Override – Cannot modify header information’ is closed to new replies.