Multi Vendor Marketplace Plugin | WCFM Marketplace › Forums › WCFM – Feature Request › Custom field for vendor settings
Tagged: custom field, filter, vendor page
- This topic has 5 replies, 2 voices, and was last updated 5 years, 5 months ago by WCFM Forum.
- AuthorPosts
- June 5, 2019 at 4:13 pm #66015matthias.kochParticipant
Hello,
I am not sure whether there is a bug or I missed something in my attempt to add a custom settings field to the vendor settings page.
I used this hook
add_filter('wcfm_marketplace_settings_fields_general', array($this, 'add_allow_invoice'), 20);
to add a checkbox like this:function add_allow_invoice($settings_fields_general){ $vendor_id = $settings_fields_general['vendor_id']['value']; $vendor_data = get_user_meta( $vendor_id, 'wcfmmp_profile_settings', true ); if( !$vendor_data ) $vendor_data = array(); $allow_invoice = isset( $vendor_data['allow_invoice'] ) ? esc_attr( $vendor_data['allow_invoice'] ) : 'no'; $settings_fields_general['allow_invoice'] = array( 'label' => __( 'Rechnung erlauben', 'ddwoo' ), 'type' => 'checkbox', 'priority' => 50, 'class' => 'wcfm-checkbox wcfm_ele', 'label_class' => 'wcfm_title wcfm_ele', 'value' => 'yes', 'dfvalue' => $allow_invoice ); return $settings_fields_general; }
So far, so good, the checkbox appears and I can check it. When I check it and save it, the value gets stored.
However, if I uncheck the previously checked box and save the form, the value does not get set to “no”, because the “wcfm_settings_form” in “data” in line 147 in the file \wp-content\plugins\wc-frontend-manager\assets\js\vendors\wcfm-script-vendors-manage.js does not contain the checkbox at all. During runtime, it is only included in the serialized form when I checked it.
Without having digged deeper so far, I assume, for fields added via the filter, there is an issue with checkboxes once they are unchecked.
Could you please have a look at the issue? I would be very happy if you could help me. 🙂Thank you and best regards
Matthias - June 6, 2019 at 6:52 pm #66261WCFM ForumMember
HI,
Please use this code save this field separately –
add_action( 'wcfm_vendor_settings_update', function( $vendor_id, $wcfm_settings_form ) { global $WCFM, $WCFMmp; if( isset( $wcfm_settings_form['allow_invoice'] ) ) { update_user_meta( $vendor_id, 'allow_invoice', 'yes' ); } else { update_user_meta( $vendor_id, 'allow_invoice', 'yes' ); } }, 500, 2 );
and directly read from meta –
get_user_meta( $vendor_id, 'allow_invoice', true );
Thank You
- June 7, 2019 at 6:16 am #66361matthias.kochParticipant
Thank you for your reply! This brings me already one step forward.
Sadly, I have one more issue:
function save_custom_vendor_settings($vendor_id, $wcfm_settings_form) { global $WCFM, $WCFMmp; if( isset( $wcfm_settings_form['allow_invoice'] ) ) { $a = $wcfm_settings_form['allow_invoice']; //ISSUE: Always "yes" update_user_meta( $vendor_id, 'allow_invoice', $wcfm_settings_form['allow_invoice'] ); } else { update_user_meta( $vendor_id, 'allow_invoice', 'no' ); } }
In the line where (for testing only) I set the $a variable, I notice that the value of
$wcfm_settings_form['allow_invoice']
is always “yes”, even though I have the checkbox unchecked.
Did I miss something else?Thank you again for your support!
Regards
Matthias - June 10, 2019 at 9:06 pm #66852WCFM ForumMember
HI,
Sorry, my code was wrong. Here is corrected one –
add_action( 'wcfm_vendor_settings_update', function( $vendor_id, $wcfm_settings_form ) { global $WCFM, $WCFMmp; if( isset( $wcfm_settings_form['allow_invoice'] ) ) { update_user_meta( $vendor_id, 'allow_invoice', 'yes' ); } else { update_user_meta( $vendor_id, 'allow_invoice', 'no' ); } }, 500, 2 );
Thank You
- June 12, 2019 at 11:07 am #67181matthias.kochParticipant
This works perfectly now, thank you very much!
- June 13, 2019 at 5:39 pm #67415WCFM ForumMember
Glad to here, you are welcome 🙂
- AuthorPosts
- The topic ‘Custom field for vendor settings’ is closed to new replies.