Skip to content

Instantly share code, notes, and snippets.

@mahbubme
Last active October 4, 2016 21:42
Show Gist options
  • Save mahbubme/7628350bff674552de0a840142c22912 to your computer and use it in GitHub Desktop.
Save mahbubme/7628350bff674552de0a840142c22912 to your computer and use it in GitHub Desktop.
WP User Frontend
<?php
/**
* Add and update custom field through Action Hook in registration form. Paste this code in the functions.php . You should create action hook "wpuf_registration_form_hook" in the registration field.
*
* @param int $form_id
* @param null|int $user_id
* @param array $form_settings
*/
function render_registration_form_hook( $form_id, $user_id, $form_settings ) {
$value = '';
if ( $user_id ) {
$value = get_user_meta( $user_id, 'wpuf_user_father_name', true );
}
?>
<div class="wpuf-label">
<label>Father Name</label>
</div>
<div class="wpuf-fields">
<input type="text" name="wpuf_user_father_name_field" value="<?php echo esc_attr( $value ); ?>">
</div>
<?php
}
add_action( 'wpuf_registration_form_hook', 'render_registration_form_hook', 10, 3 );
/**
* Update the custom field when the form submits
*
* @param type $post_id
*/
function update_father_name_hook( $user_id ) {
if ( isset( $_POST['wpuf_user_father_name_field'] ) ) {
update_user_meta( $user_id, 'wpuf_user_father_name', $_POST['wpuf_user_father_name_field'] );
}
}
add_action( 'user_register', 'update_father_name_hook' );
add_action( 'profile_update', 'update_father_name_hook' );
@media (max-width: 767px) {
table.wpuf-table thead th, table.wpuf-table th {
font-size: 10px;
padding: 9px 5px;
}
table.wpuf-table td {
padding: 6px 5px;
font-size: 10px;
}
}
<?php
/**
*If you want to set the product type ( e.g booking ) automatically when the form is submitted please follow the instruction given below.
*1) Add a hidden field in the form and insert the meta key name 'product_type' and meta value 'booking'. Check the screenshot.
*2) Paste the following code in the theme functions.php
**/
add_action('wpuf_add_post_after_insert', 'default_booking_type_product');
add_action('wpuf_edit_post_after_update', 'default_booking_type_product');
function default_booking_type_product( $post_id ) {
wp_set_object_terms( $post_id, 'booking', 'product_type' );
}
?>
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment