Home Forums Theme Support Dokan Add custom fields to existing form on Dokan

This topic is: not resolved

This topic contains 16 replies, has 3 voices, and was last updated by  Sk 3 years, 10 months ago.

Viewing 15 posts - 1 through 15 (of 17 total)
  • Author
    Posts
  • #30660

    Gregório Sordi
    Member
    Post count: 152

    Let's help each other. Make this a comunity. Share our successfull customizations, and help on some developments. Please see: http://stackoverflow.com/questions/26985251/add-custom-fields-to-existing-form-on-dokan-wordpress-woocoomerce

    Anyone know how to do this?

    #30821

    Gregório Sordi
    Member
    Post count: 152

    Can anybody give me some light?

    #30853

    Sk
    Moderator
    Post count: 371

    Hello,

    Have a look on that link. I have answered that.

    Thank you.

    #30864

    Gregório Sordi
    Member
    Post count: 152

    Great! Thanks. But this doesn't update woocommerce user address , i added, update_user_meta( $stoer_id, ‘billing_city', sanitize_text_field( $_POST[‘billing_city'] ) ); to each post on the save function and i worked!

    You are the best, man!

    #30890

    Gregório Sordi
    Member
    Post count: 152

    The only thing that is not working is the billing_state. Actually, it was changed with postcode with the original code. i changed that. but billing_state doesn't update on woocommerce user meta. Other than that it works great.

    #31362

    Gregório Sordi
    Member
    Post count: 152

    Shaikat, i really appreciate your answer. Really! But can i ask for one little more thing?

    i want to do kind of the same thing, but with a checkbox.

    code to show is:

    function greglocal($current_user) {
    	$store_id = get_current_user_id();
    	$local_pickup_enabled = get_user_meta($store_id, 'pv_local_pickup_enabled', true);
    ?>               <div class="gregcustom dokan-form-group">
                    <label class="dokan-w3 dokan-control-label" for="setting_address"><?php _e( 'Local Pickup', 'dokan' ); ?></label>
                    <div class="dokan-w5">
                    <div class="checkbox">
               <label>             <input name="pv_local_pickup_enabled" type="checkbox"
                   id="pv_local_pickup_enabled" class="<?php echo 'id_' . $store_id; ?>" value="1" <?php checked('1', get_user_meta($store_id, 'pv_local_pickup_enabled', true), $echo = true) ?>/>
            <?php
            _e('Enable Local Pickup for the shop products', 'dokan');
            ?></label>
        </div></div>
    </div>
    
    <?php } 
    
    add_filter( 'dokan_settings_after_banner', 'greglocal');

    I tried to use the method above to save this:

    
            if (isset($_POST['pv_local_pickup_enabled']) == '1') {
                update_user_meta($user_id, 'pv_local_pickup_enabled', $_POST['pv_local_pickup_enabled']);
            } else {
                update_user_meta($user_id, 'pv_local_pickup_enabled', '0');
            }
    

    but with no success. I feel the answer is right in my face and i'm not seeing it. Can you help me? I'll buy you a beer.

    #31432

    Sekander Badsha
    Member
    Post count: 2067

    Hello Gregorio,

    I have notified @Shaikat for your issue. He will review this within tomorrow. 🙂

    #31652

    Gregório Sordi
    Member
    Post count: 152

    Any news @Shaikat? =]

    #31697

    Sk
    Moderator
    Post count: 371

    Hello Gregório Sordi

    Here is your total code.

    function endereco( $current_user, $profile_info ) {
    	$pv_local_pickup_enabled = isset( $profile_info['pv_local_pickup_enabled'] ) ? esc_attr($profile_info['pv_local_pickup_enabled']) : 'no';
    	$billing_city = isset( $profile_info['billing_city'] ) ? $profile_info['billing_city'] : '';
    	$billing_postcode = isset( $profile_info['billing_postcode'] ) ? $profile_info['billing_postcode'] : '';
    	$billing_state = isset( $profile_info['billing_state'] ) ? $profile_info['billing_state'] : '';
    	$billing_address_1 = isset( $profile_info['billing_address_1'] ) ? $profile_info['billing_address_1'] : '';
    	?>       
    
    	<div class="gregcustom dokan-form-group">
            <label class="dokan-w3 dokan-control-label" for="setting_address"><?php _e( 'Local Pickup', 'dokan' ); ?></label>
            <div class="dokan-w5">
    	        <div class="checkbox">
    		           <label>             
    			           <input name="pv_local_pickup_enabled" type="checkbox"
    			               id="pv_local_pickup_enabled" class="<?php echo 'id_' . $store_id; ?>" value="yes" <?php checked( $pv_local_pickup_enabled, 'yes' ); ?>/>
    				        <?php
    				        _e('Enable Local Pickup for the shop products', 'dokan');
    		        ?></label>
    		    </div>
    	    </div>
    	</div>
    	<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_city" id="reg_billing_city" value="<?php echo $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_postcode" id="reg_billing_postcode" value="<?php echo $billing_postcode; ?>" />
    		</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_state" id="reg_billing_state" value="<?php echo $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_address_1" id="reg_billing_address_1" value="<?php echo $billing_address_1; ?>" />
    		</div>
    	</div>
    				
    	<?php
    }
    add_filter( 'dokan_settings_after_banner', 'endereco', 10, 2);
    
    /**
     * Save the extra fields.
     *
     * @param  int  $customer_id Current customer ID.
     *
     * @return void
     */
    function save_extra_endereco_fields( $store_id, $dokan_settings ) {
    
    	if (isset($_POST['pv_local_pickup_enabled'])) {
            $dokan_settings['pv_local_pickup_enabled'] = $_POST['pv_local_pickup_enabled'];
        }
    
    	if ( isset( $_POST['billing_city'] ) ) {
    		$dokan_settings['billing_city'] = $_POST['billing_city'];
    	}
    
    	if ( isset( $_POST['billing_postcode'] ) ) {
    		$dokan_settings['billing_postcode'] = $_POST['billing_postcode'];
    	}
    
    	if ( isset( $_POST['billing_state'] ) ) {
    		$dokan_settings['billing_state'] = $_POST['billing_state'];
    	}
    
    	if ( isset( $_POST['billing_address_1'] ) ) {
    		$dokan_settings['billing_address_1'] = $_POST['billing_address_1'];
    	}
    	update_user_meta( $store_id, 'dokan_profile_settings', $dokan_settings );
    }
    
    add_action( 'dokan_store_profile_saved', 'save_extra_endereco_fields', 10, 2 );

    Note: Please don't use more than one add_action in a hook for one event.

    Thank you.. 🙂

    #31728

    Gregório Sordi
    Member
    Post count: 152

    Shaikat, works great!

    many thanks man.

    how much is a beer there? Can i donate in paypal? Is it ok with forum regulations?

    #31776

    Sk
    Moderator
    Post count: 371
    This reply has been marked as private.
    #41577

    Gregório Sordi
    Member
    Post count: 152

    Hi. Sorry to reopen this post after 4 months, but i discovered an conflit with dokan seller vacation.

    when this code is active, specially the function save_extra_endereco_fields, the checkbox for “setting_go_vacation” checkbox is always unchecked. Even if i check it and all works, sellers products are inavailable and $dokan_enable_seller_vacation = get_user_meta( $user_id , ‘dokan_enable_seller_vacation', true ); is ok (value 1). The checkbox is still unchecked.

    That's a problem because seller will get confused. He is on vacation, but checkbox for go to vacation is unchecked.

    Or worse, he is on vacation, then simply save the settings again, since checkbox is unchecked, he will “get back from vacation”.

    Can i get some help in this @Shaikat?

    #42056

    Gregório Sordi
    Member
    Post count: 152

    any reply to this issue?

    #42122

    Sk
    Moderator
    Post count: 371

    Hello,

    Please provide your login details by using this form: http://wedevs.com/provide-login-details/. I will have a look what is going wrong.

    Thank you 🙂

    #42496

    Gregório Sordi
    Member
    Post count: 152
    This reply has been marked as private.
Viewing 15 posts - 1 through 15 (of 17 total)

The topic ‘Add custom fields to existing form on Dokan’ is closed to new replies.