EN

Search
Close this search box.

موستانگ، وحشیِ دوست داشتنی

پاسخ داده شد
0
0

چطور یک فیلد دلخواه (مثلاً کد ملی) را به فرم ثبت نام فروشندگان دکان اضافه کنیم؟

  • شما باید برای ارسال دیدگاه شوید
پاسخ عالی
0
0

برای ویرایش فیلدهای ثبت نام برای مشتریان ، افزونه های زیادی وجود دارد. اما برای ویرایش و اضافه کردن فیلد سفارشی به فرم ثبت نام فروشندگان می توانید به طریق زیر عمل کنید:

 

نمایش فیلد سفارشی در فرم ثبت نام فروشندگان

برای اینکار باید به فایل های روی هاست خود دسترسی داشته باشید.

1- کافی است تا فایل seller-registration-form.php را در این مسیر پیدا کنید: public_html/wp-content/plugins/dokan-lite/templates/global/seller-registration-form.php

2- فایل بالا را در پوسته theme خود (ترجیحاً child-theme) کپی کنید. یعنی این آدرس:

public_html/wp-content/themes/your_theme_name/dokan-lite/global/seller-registration-form.php

 

فیلد سفارشی در فرم ثبت نام فروشندگان دکان - موستانگ

3- کد مربوط به نمایش فیلد را در فایل  seller-registration-form.php اضافه کنید. مثلاً کد زیر:

 <p class="form-row form-group form-row-wide">
        <label for="shop-phone"><?php esc_html_e( 'GST Number', 'dokan-custom-codes' ); ?><span class="required">*</span></label>
        <input type="text" class="input-text form-control" name="gst_id" id="gst_id" value="<?php if ( ! empty( $postdata['gst_id'] ) ) echo esc_attr($postdata['gst_id']); ?>" required="required" />
    </p>

فیلد سفارشی در فرم ثبت نام فروشندگان دکان - موستانگ

*پس از اضافه کردن کد بالا، می توانید فیلد سفارشی خود را داخل فرم ثبت نام ببینید.

 

فیلد سفارشی در فرم ثبت نام فروشندگان دکان - موستانگ

 

ذخیره و نمایش فیلد در back-end

وارد فایل functions.php موجود در پوسته شوید و کد زیر را در آن قرار دهید:

function dokan_custom_seller_registration_required_fields( $required_fields ) {
    $required_fields['gst_id'] = __( 'Please enter your GST number', 'dokan-custom' );

    return $required_fields;
};

add_filter( 'dokan_seller_registration_required_fields', 'dokan_custom_seller_registration_required_fields' );


function dokan_custom_new_seller_created( $vendor_id, $dokan_settings ) {
    $post_data = wp_unslash( $_POST );

    $gst_id =  $post_data['gst_id'];
   
    update_user_meta( $vendor_id, 'dokan_custom_gst_id', $gst_id );
}

add_action( 'dokan_new_seller_created', 'dokan_custom_new_seller_created', 10, 2 );

  /* Add custom profile fields (call in theme : echo $curauth->fieldname;) */ 

add_action( 'dokan_seller_meta_fields', 'my_show_extra_profile_fields' );

function my_show_extra_profile_fields( $user ) { ?>

    <?php if ( ! current_user_can( 'manage_woocommerce' ) ) {
            return;
        }
        if ( ! user_can( $user, 'dokandar' ) ) {
            return;
        }
         $gst  = get_user_meta( $user->ID, 'dokan_custom_gst_id', true );
     ?>
         <tr>
                    <th><?php esc_html_e( 'Gst Number', 'dokan-lite' ); ?></th>
                    <td>
                        <input type="text" name="gst_id" class="regular-text" value="<?php echo esc_attr($gst); ?>"/>
                    </td>
         </tr>
    <?php
 }

add_action( 'personal_options_update', 'my_save_extra_profile_fields' );
add_action( 'edit_user_profile_update', 'my_save_extra_profile_fields' );

function my_save_extra_profile_fields( $user_id ) {

if ( ! current_user_can( 'manage_woocommerce' ) ) {
            return;
        }
    update_usermeta( $user_id, 'dokan_custom_gst_id', $_POST['gst_id'] );
}

*حالا مقدار فیلد توسط کاربر پر شده و ذخیره می شود و اگر از طریق پنل مدیریت وارد صفحه کاربر شوید ، می توانید مقدار آن را مشاهده کرده و حتی ویرایش کنید.

موستانگ

*می توانید از نام های دلخواه خود به عنوان meta key  و field name استفاده کنید (در اینجا ما از dokan_custom_gst_id  و gst_id استفاده کردیم)

  • شما باید برای ارسال دیدگاه شوید
نمایش 1 نتیجه
پاسخ شما
اگر قبلاً حساب کاربری دارید با پر کردن فیلد های زیر یا به عنوان مهمان ارسال کنید.
نام*
ایمیل*
وب سایت