• Resolved Yeso Akshith

    (@yesoakshith)


    I am trying to add a vendor store field to get data from vendor.

    I am using the below code, please go through the code and let me know what I am going wrong with.

    add_filter ( ‘wcfm_marketplace_settings_fields_general’ , ‘add_vendor_vpa’ ,20 );
    function add_vendor_vpa($settings_fields_general){

    $vendor_id = get_current_user_id();

    $vendor_data = get_user_meta( $vendor_id, ‘vendor_store_vpa’, true );

    $settings_fields_general[‘vendor_vpa’]= array(
    ‘label’ => __( ‘Virtal Payment address(VPA)/UPI ID’, ‘wc-frontend-manager’ ),
    ‘type’ => ‘text’,
    ‘priority’ => 50,
    ‘class’ => ‘wcfm-text wcfm_ele’,
    ‘label_class’ => ‘wcfm_title wcfm_ele’,
    ‘value’ => $vendor_data
    );
    return $settings_fields_general;
    }

    add_action(“wcfm_vendor_settings_update”, “update_vendor_vpa”, 10, 2);

    function update_vendor_vpa($user_id, $wcfm_settings_form){

    global $WCFM, $WCFMmp;
    if( isset( $wcfm_settings_form[“vendor_vpa”] ) ) {
    update_user_meta( $user_id, ‘vendor_store_vpa’, $wcfm_settings_form[“vendor_vpa”] );
    } else {
    update_user_meta( $user_id, ‘vendor_store_vpa’, “” );
    }

    }

    I am getting two fields one in general settings and one in brand setup only with this one code.

    When I am trying to save data, an empty string stores in usermeta, not understanding what is wrong with the code.

    And also I do not find any developer documentation regarding on how to do this. Please do share a link where I can know more on how to accomplish this.

Viewing 15 replies - 1 through 15 (of 19 total)
  • Plugin Author WC Lovers

    (@wclovers)

    Hi,

    First part of your code not right, please use this one –

    add_filter ( 'wcfm_marketplace_settings_fields_general' , 'add_vendor_vpa' ,20 );
    function add_vendor_vpa($settings_fields_general){
    	if( isset( $settings_fields_general['store_name'] ) ) {
    		$vendor_id = get_current_user_id();
    		
    		$vendor_data = get_user_meta( $vendor_id, 'vendor_store_vpa', true );
    		
    		$settings_fields_general['vendor_vpa']= array(
    		'label' => __( 'Virtal Payment address(VPA)/UPI ID', 'wc-frontend-manager' ),
    		'type' => 'text',
    		'priority' => 50,
    		'class' => 'wcfm-text wcfm_ele',
    		'label_class' => 'wcfm_title wcfm_ele',
    		'value' => $vendor_data
    		);
    	}
    	return $settings_fields_general;
    }

    Thank You

    Thread Starter Yeso Akshith

    (@yesoakshith)

    Hi

    Do you mean !isset or just isset?

    And also I guess I will have to get the vendor id from the action like

    add_filter ( ‘wcfm_marketplace_settings_fields_general’ , ‘add_vendor_vpa’ ,20, 2 );
    function add_vendor_vpa($settings_fields_general, $vendor_id )

    I see that if the below code is used, it is not working from admin store manager.

    $vendor_id = get_current_user_id();

    I would like to know if there is any documentation regarding this as it will be useful to many people who are searching for this kind of stuff.

    Plugin Author WC Lovers

    (@wclovers)

    function add_vendor_vpa($settings_fields_general, $vendor_id )

    – this is right.

    Well, there has thousands of such hook/filters.
    No ducumentation yet.

    Thank You

    Thread Starter Yeso Akshith

    (@yesoakshith)

    add_filter ( ‘wcfm_marketplace_settings_fields_general’ , ‘add_vendor_vpa’ ,20, 2 );
    function add_vendor_vpa($settings_fields_general, $vendor_id ){
    if( !isset( $settings_fields_general[‘store_name’] ) ) {

    $vendor_data = get_user_meta( $vendor_id, ‘vendor_store_vpa’, true );

    $settings_fields_general[‘vendor_vpa’]= array(
    ‘label’ => __( ‘Virtal Payment address(VPA)/UPI ID’, ‘wc-frontend-manager’ ),
    ‘type’ => ‘text’,
    ‘priority’ => 50,
    ‘class’ => ‘wcfm-text wcfm_ele’,
    ‘label_class’ => ‘wcfm_title wcfm_ele’,
    ‘value’ => $vendor_data
    );
    }
    return $settings_fields_general;

    So this is the final correct code right?

    -Well, there has thousands of such hook/filters.
    -No ducumentation yet.

    You guys are doing a great work and I know how huge the documentation can be, but I guess custom fields for store manager page needs documentation because many beginners will be at ease collecting more store regarding data through store manager.

    I appreciate the quick reply.

    Thank you.

    Plugin Author WC Lovers

    (@wclovers)

    Yeah, this code is fine. Isn’t it working for you?

    if( !isset( $settings_fields_general[‘store_name’] ) ) {
    – you may remove “!” from here.

    We have few useful code snippets here – https://docs.wclovers.com/tweaks/

    Will add more here soon ??

    Thank You

    Thread Starter Yeso Akshith

    (@yesoakshith)

    Works like charm ??

    So the final code is

    add_filter ( ‘wcfm_marketplace_settings_fields_general’ , ‘add_vendor_vpa’ ,20, 2 );
    function add_vendor_vpa($settings_fields_general, $vendor_id ){
    if( isset( $settings_fields_general[‘store_name’] ) ) {
    
    $vendor_data = get_user_meta( $vendor_id, ‘vendor_store_vpa’, true );
    
    $settings_fields_general[‘vendor_vpa’]= array(
    ‘label’ => __( ‘Virtal Payment address(VPA)/UPI ID’, ‘wc-frontend-manager’ ),
    ‘type’ => ‘text’,
    ‘priority’ => 50,
    ‘class’ => ‘wcfm-text wcfm_ele’,
    ‘label_class’ => ‘wcfm_title wcfm_ele’,
    ‘value’ => $vendor_data
    );
    }
    return $settings_fields_general;
    }

    For people who want to know how to update the field to database use the below code

    add_action("wcfm_vendor_settings_update", "update_vendor_vpa", 10, 2);
    
    function update_vendor_vpa($user_id, $wcfm_settings_form){
    	
    	global $WCFM, $WCFMmp;
    	
    	    update_user_meta( $user_id, 'wcfm_vendor_vpa_key',  $wcfm_settings_form["vendor_vpa"] );
    	
    	
    	
    }

    Thank you.

    Plugin Author WC Lovers

    (@wclovers)

    Thanks for posting final codes, will really helpful for others.

    Really appreciate your cooperation.

    Please be safe and take care ??

    Thread Starter Yeso Akshith

    (@yesoakshith)

    Hi

    I am not able to do the same with the checkbox.

    Any code references?

    Thank you

    Regards
    Yeso Akshith
    Designated Partner
    WebyTechs

    Plugin Author WC Lovers

    (@wclovers)

    Hi,

    What you are trying to do?

    Thank You

    Thread Starter Yeso Akshith

    (@yesoakshith)

    Hi I am trying to create a checkbox instead of textbox by using the code as below

    add_filter ( ‘wcfm_marketplace_settings_fields_general’ , ‘add_vendor_vpa’ ,20, 2 );
    function add_vendor_vpa($settings_fields_general, $vendor_id ){
    if( isset( $settings_fields_general[‘store_name’] ) ) {
    
    $vendor_data = get_user_meta( $vendor_id, ‘vendor_store_vpa’, true );
    
    $settings_fields_general[‘vendor_vpa’]= array(
    ‘label’ => __( ‘Virtal Payment address(VPA)/UPI ID’, ‘wc-frontend-manager’ ),
    ‘type’ => ‘checkbox’,
    ‘priority’ => 50,
    ‘class’ => ‘wcfm-text wcfm_ele’,
    ‘label_class’ => ‘wcfm_title wcfm_ele’,
    ‘value’ => $vendor_data
    );
    }
    return $settings_fields_general;
    }
    
    add_action("wcfm_vendor_settings_update", "update_vendor_vpa", 10, 2);
    
    function update_vendor_vpa($user_id, $wcfm_settings_form){
    	
    	global $WCFM, $WCFMmp;
    if(isset( $wcfm_settings_form["vendor_vpa"] ) && !empty($wcfm_settings_form['vendor_vpa']) ){	
    	    update_user_meta( $user_id, 'wcfm_vendor_vpa_key',  "yes" );
    	}else{
    update_user_meta( $user_id, 'wcfm_vendor_vpa_key',  "no" );
    }
    	
    	
    }

    When executing and selecting the checkbox it goes to YES and later on when deselected it never goes to NO

    I hope I am clear.

    Thank you

    Regards
    Yeso Akshith
    Designated Partner
    WebyTechs

    Thread Starter Yeso Akshith

    (@yesoakshith)

    Hi

    I have made changes in code as follows

    if( isset( $settings_fields_general[‘store_name’] ) ) {
    
    $vendor_data = get_user_meta( $vendor_id, ‘vendor_store_vpa’, true );
    
    $settings_fields_general[‘vendor_vpa’]= array(
    ‘label’ => __( ‘Virtal Payment address(VPA)/UPI ID’, ‘wc-frontend-manager’ ),
    ‘type’ => ‘checkbox’,
    ‘priority’ => 50,
    'class' => 'wcfm-checkbox wcfm_ele',
    'label_class' => 'wcfm_title checkbox_title wcfm_ele',
    'value' => 'yes', 
    'dfvalue' => $vendor_data 
    );
    }
    return $settings_fields_general;
    }

    Even though there is no change in the result.

    Plugin Author WC Lovers

    (@wclovers)

    Hi,

    You have written perfect code, great job ??

    Well, as I see only one mistake –

    You are saving this field using meta key “wcfm_vendor_vpa_key” –

    update_user_meta( $user_id, ‘wcfm_vendor_vpa_key’, “no” );

    But fetch using some other meta key “vendor_store_vpa” –

    $vendor_data = get_user_meta( $vendor_id, ‘vendor_store_vpa’, true );

    So, it’s not working for you. Use same meta key for both the purposes.

    Thank you and please be safe!

    Thread Starter Yeso Akshith

    (@yesoakshith)

    Hi

    I have changed the meta key and also no luck. I have cross checked if it is changed in the database to NO anytime, but it is always YES in the database.

    Please try it and get back.

    WFCM Version: 6.4.8

    Wordpress 5.4.1

    Active theme twenty twenty

    Active Plugins WCFM – WooCommerce Frontend Manager, WCFM – WooCommerce Multivendor Marketplace, WooCommerce

    Is there any possibility to go with my own html and php instead of this array kind of things?

    Thank you

    Regards
    Yeso Akshtih
    WebyTechs

    Plugin Author WC Lovers

    (@wclovers)

    Hi,

    Is there any possibility to go with my own html and php instead of this array kind of things?

    – Sure, you may do so. But then it will not match with existing dashboard design.

    Between, I have test your this code and it works perfect in my environment –

    add_filter ( 'wcfm_marketplace_settings_fields_general' , 'add_vendor_vpa' ,20, 2 );
    function add_vendor_vpa($settings_fields_general, $vendor_id ){
    	if( isset( $settings_fields_general['store_name'] ) ) {
    		$vendor_data = get_user_meta( $vendor_id, 'wcfm_vendor_vpa_key', true );
    		$settings_fields_general['vendor_vpa']= array(
    		'label' => __( 'Virtal Payment address(VPA)/UPI ID', 'wc-frontend-manager' ),
    		'type' => 'checkbox',
    		'priority' => 50,
    		'class' => 'wcfm-checkbox wcfm_ele',
    		'label_class' => 'wcfm_title checkbox_title wcfm_ele',
    		'value' => 'yes', 
    		'dfvalue' => $vendor_data 
    		);
    	}
    	return $settings_fields_general;
    }
    
    add_action("wcfm_vendor_settings_update", "update_vendor_vpa", 10, 2);
    function update_vendor_vpa($user_id, $wcfm_settings_form){
    	global $WCFM, $WCFMmp;
    	if(isset( $wcfm_settings_form["vendor_vpa"] ) && !empty($wcfm_settings_form['vendor_vpa']) ){	
    		update_user_meta( $user_id, 'wcfm_vendor_vpa_key',  "yes" );
    	} else{
    		update_user_meta( $user_id, 'wcfm_vendor_vpa_key',  "no" );
    	}
    }

    Try this full code once.

    Thank You

    Thread Starter Yeso Akshith

    (@yesoakshith)

    Hi

    I have tried the total code and it is the same as mine but yet I have copied it all and tried. The meta value of “wcfm_vendor_vpa_key” is always “yes” in database. Don’t know why.

    I tried googling this issue and google always leads me to the following page with the exact same issue.

    https://wclovers.com/forums/topic/bug-custom-field-for-vendor-settings-uncheck-a-checkbox/

    Please tell me the option to hard code it, as I am not able to figure our what action to go with.

    Thank you

    Regards
    Yeso Akshith
    WebyTechs

Viewing 15 replies - 1 through 15 (of 19 total)
  • The topic ‘WCFM wcfm_marketplace_settings_fields_general not working’ is closed to new replies.