Add new filed for the storefront section

WCMp Vendor Frontend Reports

Add new filed for the storefront section Resolved

Viewing 11 reply threads
  • Author
    Posts
    • #91982
      itunes_schreiber
      Participant

      Hi,
      I’m trying to add a new field inside the storefront. This was not a problem.

      I have added inside the shop-front.php following code (as template I have used the “vendor_description”):

      <div class="form-group">
          <label class="control-label col-sm-3 col-md-3"><?php _e('payment official options', 'dc-woocommerce-multi-vendor'); ?></label>
              <div class="col-md-6 col-sm-9">
                  <?php $vendor_paymentopen = isset($vendor_paymentopen['value']) ? $vendor_paymentopen['value'] : '';
                  $WCMp->wcmp_wp_fields->dc_generate_form_field(array("vendor_paymentopen" => array('name' => 'vendor_paymentopen', 'type' => $field_type, 'class' => 'no_input form-control regular-textarea', 'value' => $vendor_paymentopen, 'settings' => $_wp_editor_settings))); ?>
                  <!--textarea class="no_input form-control" name="vendor_paymentopen" cols="" rows=""><?php //echo isset($vendor_paymentopen['value']) ? $vendor_paymentopen['value'] : ''; ?></textarea-->
      	</div>
      </div>
      Copy

      But I’m now not able to fill these field and save it?
      Do I also need to customize the database?

      Regards,
      Lukas.

    • #92023

      Hi Lukas, thanks for the query.

      You have added the field to display the fields. However, you have to save those field using this action before_wcmp_vendor_dashboard. You can find further info here : https://github.com/wcmarketplace/dc-woocommerce-multi-vendor/blob/52a5866e9548edc51cf9937bec92a5c299b0df57/classes/class-wcmp-vendor-hooks.php

    • #92034
      itunes_schreiber
      Participant

      Hi,

      thanks as always for your fast respond. Very great support. 🙂
      Can you please assist me with some code?

      I have found your code from another post to get an idea how I need to use the before_wcmp_vendor_dashboard action:
      https://wc-marketplace.com/support-forum/topic/imprint-for-vendors/#post-35836

      So in my case, would this code work for me (at least almost :D)?

      add_action( 'before_wcmp_vendor_dashboard', 'save_vendor_paymentopen' );
      
      function save_vendor_paymentopen() {
         if( $_SERVER['REQUEST_METHOD'] == 'POST' && isset($_POST['vendor_paymentopen'])  ) {
         	if(isset( $_POST['vendor_paymentopen'] ) ) {
         	$vendor_id = get_current_vendor_id();
         	update_user_meta( $vendor_id, '_vendor_paymentopen', $_POST['vendor_paymentopen'] );
         	}
         }
      }
      Copy

      I’m also quite not sure where I need to paste this code? Also inside the shop-front.php or in the lass-wcmp-vendor-hooks.php file?
      Thank you very much.

    • #92085

      @itunes_schreiber, you need to add the code in the function.php of the current active theme.

    • #92092
      itunes_schreiber
      Participant

      Hi,
      I’m using following code inside the function.php but the data still won’t be saved after I click on save.
      The code is almost the same as the one above (little customization). Could you please assist with the code?

      add_action( 'before_wcmp_vendor_dashboard', 'save_vendor_paymentopen' );
      
      function save_vendor_paymentopen() {
         if( $_SERVER['REQUEST_METHOD'] == 'POST' && isset($_POST['store_save_vendor'])  ) {
         	if(isset( $_POST['vendor_paymentopen'] ) ) {
         	$vendor_id = get_current_vendor_id();
         	update_user_meta( $vendor_id, '_vendor_paymentopen', $_POST['vendor_paymentopen'] );
         	}
         }
      }
      Copy

      Thanks. 🙂

    • #92193

      Hi, please use this updated code :

      add_action( 'wcmp_after_shop_front', 'extra_setting_fields' );
      	/*form for vendor dashboard set field*/
      	function extra_setting_fields() { 
      		$vendor_id = get_current_vendor_id();
      		$vendor_paymentopen = ( metadata_exists( 'user', $vendor_id, '_vendor_set_payment_oficial' ))? get_user_meta( $vendor_id, '_vendor_set_payment_oficial', true ):'';
      		?>
      			<div class="panel panel-default pannel-outer-heading">
      	            <div class="panel-heading">
      	                <h3><?php _e('Vendor Options', 'dc-woocommerce-multi-vendor'); ?></h3>
      	            </div>
      	            <div class="panel-body panel-content-padding form-horizontal">
      	                <div class="wcmp_media_block">
      	                	<div class="form-group">
      	                        <label class="control-label col-sm-3 col-md-3"><?php _e('Set payment official options', 'dc-woocommerce-multi-vendor'); ?></label>
      	                        <div class="col-md-6 col-sm-9">
      	                            <input class="form-control" type="number"  name="set_payment_oficial" value="<?php echo $vendor_paymentopen ; ?>">
      	                        </div>  
      	                    </div>
      	                </div>
      	            </div>
      	        </div>
      	    <?php 
      	}
      
      	add_action('before_wcmp_vendor_dashboard', 'save_vendor_dashboard_data_payment');
      	/*save vendor dashboard data into user_meta*/
      	function save_vendor_dashboard_data_payment(){
      		global $WCMp;
      	    $vendor_id = get_current_vendor_id();
      	    if($_SERVER['REQUEST_METHOD'] == 'POST') {
      	        if($WCMp->endpoints->get_current_endpoint() == 'storefront') {
      	           if($_POST['set_payment_oficial']){
      	           		$min_order_amount = absint($_POST['set_payment_oficial']);
      	               ( metadata_exists( 'user', $vendor_id, '_vendor_set_payment_oficial' ))? update_user_meta( $vendor_id, '_vendor_set_payment_oficial', $min_order_amount ):add_user_meta( $vendor_id, '_vendor_set_payment_oficial', $min_order_amount );	
      	           }
      	        }
      	    }
      	}
      Copy
    • #92199
      itunes_schreiber
      Participant

      Hi Moumita,
      thank you very much for your help. 🙂

      I have customized the code a little bit (code at the end of the post), because I need that this field is a textarea.

      Some more questions regarding this:
      1. How can I change the code, that the wp-editor can be used for this extra field (as “Shop-description” & “message to the buyer”)?
      2. Is it also possible to display the field anywhere else and not only at the bottom? For example between shop-slug-name & shop-description or above the Shopfront –> general (above the shop-name)? Because this would be an important field for me / the vendor and may will be missed if it’s upcoming first after the social media stuff.
      3. Is it possible to mark the field as mandatory (as shop-slug-name)?

      Thank you and have a nice day,
      Lukas

      Code inside functions.php:

      add_action( 'wcmp_after_shop_front', 'extra_setting_fields' );
      	/*form for vendor dashboard set field*/
      	function extra_setting_fields() { 
      		$vendor_id = get_current_vendor_id();
      		$vendor_paymentopen = ( metadata_exists( 'user', $vendor_id, '_vendor_set_payment_oficial' ))? get_user_meta( $vendor_id, '_vendor_set_payment_oficial', true ):'';
      		?>
      			<div class="panel panel-default pannel-outer-heading">
      	            <div class="panel-heading">
      	                <h3><?php _e('Zusätzliche Einstellungen', 'dc-woocommerce-multi-vendor'); ?></h3>
      	            </div>
      	            <div class="panel-body panel-content-padding form-horizontal">
      	                <div class="wcmp_media_block">
      	                	<div class="form-group">
      	                        <label class="control-label col-sm-3 col-md-3"><?php _e('öffentlich einsehbare Zahlungsmöglichkeiten', 'dc-woocommerce-multi-vendor'); ?></label>
      	                        <div class="col-md-6 col-sm-9">
      	                            <input class="form-control" type="textarea" name="set_payment_oficial" value="<?php echo $vendor_paymentopen; ?>">
      	                        </div>  
      	                    </div>
      	                </div>
      	            </div>
      	        </div>
      	    <?php 
      	}
      
      	add_action('before_wcmp_vendor_dashboard', 'save_vendor_dashboard_data_payment');
      	/*save vendor dashboard data into user_meta*/
      	function save_vendor_dashboard_data_payment(){
      		global $WCMp;
      	    $vendor_id = get_current_vendor_id();
      	    if($_SERVER['REQUEST_METHOD'] == 'POST') {
      	        if($WCMp->endpoints->get_current_endpoint() == 'storefront') {
      	           if($_POST['set_payment_oficial']){
      	           		$desc = $_POST['set_payment_oficial'];
      	               ( metadata_exists( 'user', $vendor_id, '_vendor_set_payment_oficial' ))? update_user_meta( $vendor_id, '_vendor_set_payment_oficial', $desc ):add_user_meta( $vendor_id, '_vendor_set_payment_oficial', $desc );	
      	           }
      	        }
      	    }
      	}
      Copy
    • #92202
      itunes_schreiber
      Participant

      Update (cant edit my post above):

      I was able to implement the use of wp-editor for the field. 🙂
      Therefore only the 2nd and the 3rd point ist still not sure, there I would still need your assist:

      2. Is it also possible to display the field anywhere else and not only at the bottom? For example between shop-slug-name & shop-description or above the Shopfront –> general (above the shop-name)? Because this would be an important field for me / the vendor and may will be missed if it’s upcoming first after the social media stuff.

      3. Is it possible to mark the field as mandatory (as shop-slug-name)?

      The code for 1st (may for somebody else nice to know):

      add_action( 'wcmp_after_shop_front', 'extra_setting_fields' );
      	/*form for vendor dashboard set field*/
      	function extra_setting_fields() { 
      		global $WCMp;
      		$vendor_id = get_current_vendor_id();
      		$vendor_paymentopen = 'demo-text';
      		$vendor_paymentopen = get_user_meta($vendor_id, '_vendor_set_payment_oficial', true) ? get_user_meta($vendor_id, '_vendor_set_payment_oficial', true) : $vendor_paymentopen;
      		
      		    $_wp_editor_settings = array('tinymce' => true);
          		    if (!$WCMp->vendor_caps->vendor_can('is_upload_files')) {
           			$_wp_editor_settings['media_buttons'] = false;
        			} ?>
      
      			<div class="panel panel-default pannel-outer-heading">
      	            <div class="panel-heading">
      	                <h3><?php _e('additional setting', 'dc-woocommerce-multi-vendor'); ?></h3>
      	            </div>
      	            <div class="panel-body panel-content-padding form-horizontal">
      	                <div class="wcmp_media_block">
      	                	<div class="form-group">
      	                        <label class="control-label col-sm-3 col-md-3"><?php _e('public payment methods:', 'dc-woocommerce-multi-vendor'); ?></label>
      	                        <div class="col-md-6 col-sm-9">
      								<?php $WCMp->wcmp_wp_fields->dc_generate_form_field(array("vendor_paymentopen" => array('name' => 'vendor_paymentopen', 'type' => 'wpeditor', 'class' => 'regular-textarea', 'value' => $vendor_paymentopen, 'settings' => $_wp_editor_settings))); ?>
      	                        </div>  
      	                    </div>
      	                </div>
      	            </div>
      	        </div>
      	    <?php 
      	}
      
      	add_action('before_wcmp_vendor_dashboard', 'save_vendor_dashboard_data_payment');
      	/*save vendor dashboard data into user_meta*/
      	function save_vendor_dashboard_data_payment(){
      	    $vendor_id = get_current_vendor_id();
      	    if($_SERVER['REQUEST_METHOD'] == 'POST') {
      			if(isset( $_POST['vendor_paymentopen'] ) ) {
      				$vendor_id = get_current_vendor_id();
      				update_user_meta( $vendor_id, '_vendor_set_payment_oficial', $_POST['vendor_paymentopen'] );
      	           }
      	    	}
      		}
      Copy
    • #92285
      itunes_schreiber
      Participant

      I have just think over, this is not very urgent anymore.
      Also because I have already started to document the process for each vendor and therefore it wouldn’t be good, if the field position will be different from the documentation / live-system.

      Therefore, you can mark this as resolved. thanks. 🙂

    • #92328

      Hi, for the 2nd and 3rd point, you need to override the shop-front.php template with this : https://docs.google.com/document/d/1cWwSiOEAEVIKlDxDoKFmogwDmAL1UsgP7QCIhjQ-Xp8/edit?usp=sharing

    • #92338
      itunes_schreiber
      Participant

      Thanks for your assist Moumita.

      You can now definitively mark the ticket as resolved.

      Regards,
      Lukas

    • #92342

      We are happy to help @Lukas

Viewing 11 reply threads

The topic ‘Add new filed for the storefront section’ is closed to new replies.

COVID-19 Outbreak: WCMp team is supporting business affected by coronavirus

Read the Message Buy at Slashed Price