J
J
jazzman72018-06-30 03:33:09
WordPress
jazzman7, 2018-06-30 03:33:09

How to add a text field in woocoomerce with a default value from a php variable?

Good day.
In general, when placing an order, I want to make a text field in which the data from the session will fit by default (value). Found this code

add_action( 'woocommerce_after_order_notes', 'my_custom_checkout_field' );

function my_custom_checkout_field( $checkout ) {

 

    echo '<div id="my_custom_checkout_field"><h2>' . __('Мое поле') . '</h2>';

 

    woocommerce_form_field( 'my_field_name', array(

        'type'          => 'text',

        'class'         => array('my-field-class form-row-wide'),

        'label'         => __('Заполните это поле'),

        'placeholder'   => __('Введите здесь требуемый текст'),
  

        ), $checkout->get_value( 'my_field_name' ));

 

    echo '</div>';

 

}

added to the array did not work, what's wrong? and another field is added after the order note field, how to add it after the name (billing_first_name) ?
'value' => $_SESSION['aaa']

Answer the question

In order to leave comments, you need to log in

Didn't find what you were looking for?

Ask your question

Ask a Question

731 491 924 answers to any question