url: thefoldlondon.com
theme: Abundance 1.4
Hello Kriesi team,
I am searching for a way to incorporate a "where did you hear about us?" radio form on the checkout page.
Apart from the different options offered to the user to select, it would be ideal to also include a text box for the user to fill in when none of the offered options are right for him.
plz see image here > http://screencast.com/t/cVEOOrRYF8
of course this whole form would not be mandatory in order for the user to place the order.
I did get in touch with Woo with the same question; the suggested code to be implemented on the functions.php was this:
/**
* Outputs a rasio button form field
*/
function woocommerce_form_field_radio( $key, $args, $value = '' ) {
global $woocommerce;
$defaults = array(
'type' => 'radio',
'label' => '',
'placeholder' => '',
'required' => false,
'class' => array() ,
'label_class' => array() ,
'return' => false,
'options' => array()
);
$args = wp_parse_args( $args, $defaults );
if ( ( isset( $args['clear'] ) && $args['clear'] ) ) $after = '<div class="clear"></div>'; else $after = '';
$required = ( $args['required'] ) ? ' <abbr class="required" title="' . esc_attr__( 'required', 'woocommerce' ) . '">*</abbr>' : '';
switch ( $args['type'] ) {
case "select" :
$options = '';
if ( ! empty( $args['options'] ) )
foreach ( $args['options'] as $option_key => $option_text )
$options .= '<input type="radio" name="' . $key . '" id="' . $key . '" value="' . $option_key . '" '. selected( $value, $option_key, false ) . 'class="select">' . $option_text .'' . "\r\n";
$field = '<p class="form-row ' . implode( ' ', $args['class'] ) .'" id="' . $key . '_field">
<label for="' . $key . '" class="' . implode( ' ', $args['label_class'] ) .'">' . $args['label']. $required . '</label>
' . $options . '
</p>' . $after;
break;
}
if ( $args['return'] ) return $field; else echo $field;
}
/**
* Add the field to the checkout
**/
add_action('woocommerce_after_order_notes', 'hear_about_us_field');
function hear_about_us_field( $checkout ) {
echo '<div id="hear_about_us_field"><h3>'.__('How did you hear about us?').'</h3>';
woocommerce_form_field_radio( 'hear_about_us', array(
'type' => 'select',
'class' => array('here-about-us form-row-wide'),
'label' => __(''),
'placeholder' => __(''),
'required' => true,
'options' => array(
'Ask Jeeves' => 'Ask Jeeves',
'BBC Website' => 'BBC Website',
'Bing' => 'Bing',
)
), $checkout->get_value( 'hear_about_us' ));
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['hear_about_us'])
$woocommerce->add_error( __('Please enter something into this new shiny field.') );
}
/**
* Update the order meta with field value
**/
add_action('woocommerce_checkout_update_order_meta', 'hear_about_us_field_update_order_meta');
function hear_about_us_field_update_order_meta( $order_id ) {
if ($_POST['hear_about_us']) update_post_meta( $order_id, 'How did you hear about us?', esc_attr($_POST['hear_about_us']));
}
sadly enough the above code did not work, instead it caused a complete site crash, with this error:
Parse error: syntax error, unexpected T_CONSTANT_ENCAPSED_STRING in /home/.../.../wp-content/themes/abundance/functions.php on line 279!
note: btw there is no line 279 on theme's function.php file if i am right!
I could really count on some help with this from the team, you ve been great so far!
Thank you in advance,
Best,
Bill














