Skip to content

Instantly share code, notes, and snippets.

@bentasm1
Forked from digitalchild/functions.php
Last active June 8, 2017 14:21
Show Gist options
  • Save bentasm1/9e017d7a102e82cda1b0 to your computer and use it in GitHub Desktop.
Save bentasm1/9e017d7a102e82cda1b0 to your computer and use it in GitHub Desktop.
Add a custom field to the store settings page for WCVendors Pro
This code adds a custom field to the Dashboard > Settings page for your vendors to
provide you extra bits of info you may need from them. Duplicate for each custom field you need,
renaming the meta keys and functions each time so they are not duplicated.
Part #1 - Theme functions.php file:
/* WC Vendors Pro - My Custom Field */
function store_bank_details( ){
if ( class_exists( 'WCVendors_Pro' ) ){
$key = '_wcv_custom_settings_bankname';
$value = get_user_meta( get_current_user_id(), $key, true );
// Bank Name
WCVendors_Pro_Form_Helper::input( array(
'id' => $key,
'label' => __( 'Bank Name', 'wcvendors-pro' ),
'placeholder' => __( 'First Bank', 'wcvendors-pro' ),
'desc_tip' => 'true',
'description' => __( 'Your local bank name', 'wcvendors-pro' ),
'type' => 'text',
'value' => $value,
)
);
}
}
Part 2: This adds the custom field to the wp-admin > Users > Edit User screen, if you need it to, and also goes in your
themes functions.php file:
add_action( 'wcvendors_admin_after_commission_due', 'wcv_store_bank_details_admin' );
function wcv_store_bank_details_admin( $user ) {
?>
<tr>
<th><label for="_wcv_custom_settings_bankname"><?php _e( 'Bank Name', 'wcvendors-pro' ); ?></label></th>
<td><input type="text" name="_wcv_custom_settings_bankname" id="_wcv_custom_settings_bankname" value="<?php echo get_user_meta( $user->ID, '_wcv_custom_settings_bankname', true ); ?>" class="regular-text"></td>
</tr>
<?php
}
?>
Part 3: In order to show the custom field on your Pro Settings page, you need to add the function you just created above to the
template. Copy /plugins/wc-vendors-pro/templates/dashboard/store-settings.php to /themes/yourtheme-child/wc-vendors/dashboard/store-settings.php
and add this wherever you want the field to show up:
<?php store_bank_details( ); ?>
Done! That's it. Have fun.
@juancarlosqr
Copy link

juancarlosqr commented May 25, 2017

Hi @bentasm1, I think you forgot to mention something very important here:

The right action name to hook into this is wcv_pro_store_settings_saved because the action wcvendors_shop_settings_saved described in the doc from this gist doesn't work for the PRO plugin. Half day figuring this out. Please update this, so others don't go through the same.

Usage:

add_action( 'wcv_pro_store_settings_saved', 'SAVING_FUNCTION_NAME_HERE' );

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment