hello I was trying to make text box on the page read-only and I tried what exactly what I think is enough but the text box still writeable and I still confused and don’t know what I missed there.
I tried to write
'readonly' => true,
'readonly' => 'true',
'readonly' => 'readonly',
and all didn’t worked for me 🙁
function my_custom_checkout_field( $checkout ){
echo '<div id="EATM_custom_checkout_field">';
echo '<input class="EATM_checkout_exchange_rate" value="'.$this->exchange_data['EATM_exchange_rate'].'" hidden/>';
echo sprintf('<div class="EATM_container-payments"><div class="EATM_container-image-checkout"><img src="%1$s" /></div>',$this->payment_images[ str_replace(' ','_',$this->exchange_data['EATM_payment_send_from']) ] );
echo "<div class='payment'>";
woocommerce_form_field( 'my_field_name_1', array(
'type' => 'text',
'class' => array('my-field-class form-row-wide'),
'label' => __('ارسال'),
'required' =>true,
'readonly' =>true,
'value' =>$this->exchange_data['EATM_payment_send_from'],
'placeholder' => __('Send'),
), $this->exchange_data['EATM_payment_send_from']);
2
Answers
To make a textbox readonly add
like this
use the
custom_attributes
tag:Also, I think the
value
field should bedefault
or use the last parameter (like you are doing) and remove the value line entirely.Documentation here: https://rudrastyh.com/woocommerce/woocommerce_form_field.html