Я пытаюсь добавить настраиваемые поля в Dokan (плагин woocommerce - http://demo.wedevs.com/dokan/) настройки продавца для редактирования значений с адреса пользователя в woocommerce. У Докана есть форма на интерфейсе, где продавцы могут редактировать настройки своего магазина. Я изменил свои темы functions.php с помощью этого кода:
<?php
function endereco() {
$user_id = get_current_user_id();
?> <div class="gregcustom dokan-form-group">
<label class="dokan-w3 dokan-control-label" for="setting_address"><?php _e( 'Cidade', 'dokan' ); ?></label>
<div class="dokan-w5">
<input type="text" class="dokan-form-control input-md valid" name="billing_first_name" id="reg_billing_first_name" value="<?php echo esc_attr_e( $_POST['billing_city'] ); ?>" />
</div> </div>
<div class="gregcustom dokan-form-group">
<label class="dokan-w3 dokan-control-label" for="setting_address"><?php _e( 'Estado', 'dokan' ); ?></label>
<div class="dokan-w5">
<input type="text" class="dokan-form-control input-md valid" name="billing_first_name" id="reg_billing_first_name" value="<?php esc_attr_e( $_POST['billing_state'] ); ?>" />
</div>
</div>
<div class="gregcustom dokan-form-group">
<label class="dokan-w3 dokan-control-label" for="setting_address"><?php _e( 'CEP', 'dokan' ); ?></label>
<div class="dokan-w5">
<input type="text" class="dokan-form-control input-md valid" name="billing_first_name" id="reg_billing_first_name" value="<?php esc_attr_e( $_POST['billing_postcode'] ); ?>" />
</div> </div>
<div class="gregcustom dokan-form-group">
<label class="dokan-w3 dokan-control-label" for="setting_address"><?php _e( 'Endereço', 'dokan' ); ?></label>
<div class="dokan-w5">
<input type="text" class="dokan-form-control input-md valid" name="billing_first_name" id="reg_billing_first_name" value="<?php esc_attr_e( $_POST['billing_address_1'] ); ?>" />
</div>
</div>
<?php
}
add_filter( 'dokan_settings_after_banner', 'endereco');
/**
* Save the extra fields.
*
* @param int $customer_id Current customer ID.
*
* @return void
*/
function save_extra_endereco_fields( $customer_id ) {
if ( isset( $_POST['billing_city'] ) ) {
// WordPress default first name field.
update_user_meta( $customer_id, 'billing_city', sanitize_text_field( $_POST['billing_city'] ) );
}
if ( isset( $_POST['billing_postcode'] ) ) {
// WordPress default last name field.
update_user_meta( $customer_id, 'billing_postcode', sanitize_text_field( $_POST['billing_postcode'] ) );
}
if ( isset( $_POST['billing_state'] ) ) {
// WooCommerce billing phone
update_user_meta( $customer_id, 'billing_state', sanitize_text_field( $_POST['billing_address_1'] ) );
}
if ( isset( $_POST['billing_address_1'] ) ) {
// WooCommerce billing phone
update_user_meta( $customer_id, 'billing_address_1', sanitize_text_field( $_POST['billing_address_1'] ) );
}
}
add_action( 'dokan_store_profile_saved', 'save_extra_endereco_fields' );
Форма отображается нормально, но не обновляет метаданные пользователя. Еще одна вещь, которую я не смог сделать без ошибок, - это показать текущее значение в поле ввода формы.
я думаю, что это довольно просто для хорошего программиста. Может кто-нибудь мне помочь? Большое спасибо.