Answer the question
In order to leave comments, you need to log in
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>';
}
'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 questionAsk a Question
731 491 924 answers to any question