Empresas
Empregos
  • Sobre nós
  • Soluções
    • Publicação de vagas
      Publique sua vaga e receba candidatos qualificados em 48h.
    • Avaliações de candidatos
      Mais de 500 testes técnicos e psicológicos, mais anti-fraude.
    • Headhunting
      Busca executiva personalizada do início ao fim.
    • Folha de Pagamento + EOR
      Dispersão de folha e EOR em mais de 15 países da LATAM.
  • Preços
  • Empregos

0

133
Visualizações
Read Only field not displaying information

We have an ecommerce website where we can't allow the users to edit their shipping address, but would like them to able to store multiple addresses from a drop down. I used the following code to make the shipping address read only and not editable, but when they select a different address from the drop down the readonly fields do not update. I tried the disabled attribute which worked visually, but we need the data to POST when placing an order. Is there any work around for this?

jQuery(document).ready(function ($) {
  $("#shipping_last_name").attr("readonly", true);
});
about 4 years ago · Juan Pablo Isaza
1 Respostas
Responde à pergunta

0

/** * Adds the address book select to the checkout page. * * @since 1.0.0 * * @param array $fields An array of WooCommerce Shipping Address fields. * @return array */ public function shipping_address_select_field( $fields ) { if ( is_user_logged_in() ) { $address_book = $this->get_address_book();

        $address_selector['address_book'] = array(
            'type'     => 'select',
            'class'    => array( 'form-row-wide', 'address_book' ),
            'label'    => __( 'Address Book', 'woo-address-book' ),
            'order'    => -1,
            'priority' => -1,
        );

        if ( ! empty( $address_book ) && false !== $address_book ) {
            foreach ( $address_book as $name => $address ) {
                if ( ! empty( $address[ $name . '_address_1' ] ) ) {
                    $address_selector['address_book']['options'][ $name ] = $this->address_select_label( $address, $name );
                }
            }

            $address_selector['address_book']['options']['add_new'] = __( 'Add New Address', 'woo-address-book' );

            $fields['shipping'] = $address_selector + $fields['shipping'];
            $fields['shipping']['custom_attributes'] = array('readonly'=>'readonly');
        }
    }

    return $fields;
}

/**
 * Adds the address book select to the checkout page.
 *
 * @since 1.0.0
 *
 * @param array  $address An array of WooCommerce Shipping Address data.
 * @param string $name Name of the address field to use.
 * @return string
 */
public function address_select_label( $address, $name ) {
    $label = '';

    $address_nickname = get_user_meta( get_current_user_id(), $name . '_address_nickname', true );
    if ( $address_nickname ) {
        $label .= $address_nickname . ': ';
    }

    if ( ! empty( $address[ $name . '_first_name' ] ) ) {
        $label .= $address[ $name . '_first_name' ];
    }
    if ( ! empty( $address[ $name . '_last_name' ] ) ) {
        if ( ! empty( $label ) ) {
            $label .= ' ';
        }
        $label .= $address[ $name . '_last_name' ];
    }
    if ( ! empty( $address[ $name . '_address_1' ] ) ) {
        if ( ! empty( $label ) ) {
            $label .= ', ';
        }
        $label .= $address[ $name . '_address_1' ];
    }
    
    
    if ( ! empty( $address[ $name . '_city' ] ) ) {
        if ( ! empty( $label ) ) {
            $label .= ', ';
        }
        $label .= $address[ $name . '_city' ];
    }
    if ( ! empty( $address[ $name . '_state' ] ) ) {
        if ( ! empty( $label ) ) {
            $label .= ', ';
        }
        $label .= $address[ $name . '_state' ];
    }

    return apply_filters( 'wc_address_book_address_select_label', $label, $address, $name );
}
about 4 years ago · Juan Pablo Isaza Relatório
Responde à pergunta
Encontrar trabalhos remotos

Descubra a nova forma de encontrar um emprego!

melhores empregos
Principais categorias de trabalho
Empresas
Postar vaga Preços Comercial
Jurídico
Termos e Condições Política de privacidade
© 2026 PeakU Inc. All Rights Reserved.
Andres GPT
Recomende algumas ofertas para mim
Preciso de ajuda