Form field displaying twice in checkout
-
I am using the below code at this link:
>https://bestcheapluxuryhotels.com/shop/articles-variations-test/
Here is the scenario:
– select 500
– click add to cart
– select 700
– click add to cart
– then click ‘checkout’You will find 2
Enter Keywords *
fields and 2Enter Keyword Density fields
, but there should only be 1 on each of those fields./** * Add the field to the checkout **/ add_action('woocommerce_after_order_notes', 'my_custom_checkout_field'); function my_custom_checkout_field( $checkout ){ global $woocommerce; $found = false; //check if product already in cart if ( sizeof( $woocommerce->cart->get_cart() ) > 0 ) { foreach ( $woocommerce->cart->get_cart() as $cart_item_key => $values ) { $_product = $values['data']; if ( $_product->id == 209) { //ignore this product echo '<div id="my_custom_checkout_field"><h3>'.__('My Field').'</h3>'; woocommerce_form_field( 'my_field_name', array( 'type' => 'checkbox', 'class' => array('my-field-class form-row-wide'), 'label' => __('Fill in this field'), 'placeholder' => __('Enter a number'), ), $checkout->get_value( 'my_field_name' )); echo '</div>'; } if ( $_product->id == 221) { // Here checking with product ID woocommerce_form_field( 'Keywords', array( //this is keyword field 'type' => 'textarea', 'required' => true, 'class' => array('my-field-class form-row-wide'), 'label' => __('Enter Keywords'), 'placeholder' => __('Please enter keywords'), ), $checkout->get_value( 'Keywords' )); woocommerce_form_field( 'Keyword_Density', array( //this is keyword density field 'type' => 'text', 'required' => false, 'class' => array('my-field-class form-row-wide'), 'label' => __('Enter Keyword Density'), 'placeholder' => __('Please enter keyword Density'), ), $checkout->get_value( 'Keyword_Density' )); } } } }
Could anyone please look into this?
**EDITED:** For more info see
>https://wcdocs.woothemes.com/snippets/tutorial-customising-checkout-fields-using-hooks-and-filters/
and
- The topic ‘Form field displaying twice in checkout’ is closed to new replies.