skip to Main Content

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


  1. To make a textbox readonly add

    disabled

    like this

    <input type="text" value="1" class="form-control" disabled="">
    
    Login or Signup to reply.
  2. use the custom_attributes tag:

    function my_custom_checkout_field( $checkout ){
    // ...
    
      woocommerce_form_field('my_field_name_1', array(
        'type' => 'text',
        'class' => array('my-field-class form-row-wide'),
        'label' => __('ارسال'),
        'required' => true,
        'custom_attributes' => ['readonly' => true], // or ['disabled' => true]
        'default' => $this->exchange_data['EATM_payment_send_from'],
        'placeholder' => __('Send'),
      ), $this->exchange_data['EATM_payment_send_from']);
    

    Also, I think the value field should be default 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

    Login or Signup to reply.
Please signup or login to give your own answer.
Back To Top
Search