check registration custom fields are filed by logged in user woocommerce - wordpress

In woocommerce customer registration I need to add 2 additional fields (mandatory) year of passing (select box), Name of college (select box).
I need to add these 2 fields to the registration process and prompt existing users to fill them if they try to login.
As in the process will be as follows
User tries to login (need to check whether the above fields are filled by user or not - If yes then make him logged in else proceed to step 2)
Will get registration page / form to fill in the above additional fields.
He will then get logged in to the site.
Thanks in advance

Yes, that can be done.
As per I understood, you want to add some extra fields to your registration page. Here's how:
add_action( 'register_form', 'myplugin_register_form' );
function myplugin_register_form() {
$first_name = ( ! empty( $_POST['first_name'] ) ) ? trim( $_POST['first_name'] ) : '';
?>
<p>
<label for="first_name"><?php _e( 'Full Name', 'mydomain' ) ?><br />
<input type="text" name="first_name" id="first_name" class="input" value="<?php echo esc_attr( wp_unslash( $first_name ) ); ?>" size="25" required /></label>
</p>
<?php
}
Put the code in function.php and there you go.
It will work perfectly.

Related

University Woocommerce Store - Student Number Required on Checkout

I have built a Woocommerce store for a university client for the sole purpose of selling study tours to the students twice a year. Client is requesting that on check out (or on sign up) students are required to enter their student number and this number needs to be be approved in the WordPress or Woocommerce database before the system will let them continue.
There are about 100 students that can apply, so I can unload the individual student numbers if needed (no need to link to a secondary system if this makes things easier). The students can only order 1 item from the store, so the item needs to link to their student number and once the sale is made they can not order any other products from the store. I already added single lifetime purchases plugin, but this links to their email addresses and some students then use alternative email addresses to purchase more items when they are not allowed to. They only have 1 unique student number so it should rather link to this number.
I was thinking either:
A) Upload the active student numbers and on checkout verify the number is correct and hasn't been used already, or
B) Make the students register before they can access the site and have the system check the student number is valid before hand.
Can anyone point me in the right direction?
Hands down the best, and most optimal solution for this problem would be your B) choice. Forcing students to enter their student number when registering for the site would be the best option, since the ability to then compare the value saved to their profile with the value entered on checkout would be relatively easy on the front-end side.
I can help you out with a partial solution to your problem, and that's to give you a head start on what you can do hook onto the Woo-commerce registration form to create additional fields as required:
Note: this is an example of how to add Phone Number, First Name, and Last Name to the form.
function wooc_extra_register_fields() {?>
      <p class="form-row form-row-wide">
      <label for="reg_billing_phone"><?php _e( 'Phone', 'woocommerce' ); ?></label>
      <input type="text" class="input-text" name="billing_phone" id="reg_billing_phone" value="<?php esc_attr_e( $_POST['billing_phone'] ); ?>" />
      </p>
      <p class="form-row form-row-first">
      <label for="reg_billing_first_name"><?php _e( 'First name', 'woocommerce' ); ?><span class="required">*</span></label>
      <input type="text" class="input-text" name="billing_first_name" id="reg_billing_first_name" value="<?php if ( ! empty( $_POST['billing_first_name'] ) ) esc_attr_e( $_POST['billing_first_name'] ); ?>" />
      </p>
      <p class="form-row form-row-last">
      <label for="reg_billing_last_name"><?php _e( 'Last name', 'woocommerce' ); ?><span class="required">*</span></label>
      <input type="text" class="input-text" name="billing_last_name" id="reg_billing_last_name" value="<?php if ( ! empty( $_POST['billing_last_name'] ) ) esc_attr_e( $_POST['billing_last_name'] ); ?>" />
      </p>
      <div class="clear"></div>
      <?php
}
add_action( 'woocommerce_register_form_start', 'wooc_extra_register_fields' );
You can easily edit this code and change it to one added input, namely the student number which you're looking for. Hope this helps, good luck!

Add Address fields in seller registration page of dokan plugin

I want to add address fields on seller registration page and also save this fields and updated in seller profile. I am using dokan wordpress plugin for multivendor. Please provide me suggestion and code.
Thanks in advance
Seller can input his address in the seller welcome wizard that comes immediately after registration. But if you still need this in the registration-form you need to override this registration template inside your theme /plugins/dokan/templates/global/seller-registration-form.php
Add the address fields as set in this template :
/plugins/dokan/templates/settings/address-form.php
Then use woocommerce_created_customer hook to save your $POST data accordingly.
For saving address you can check this file as reference :
/plugins/dokan/classes/template-settings.php line: 462
Thanks
<p class="form-row form-group form-row-wide">
<label for="dokan_address[city]"><?php _e( 'City', 'dokan-lite' ); ?> <span class="required">*</span></label>
<input type="text" class="input-text form-control" name="city" id="dokan_address[city]" value="<?php if ( ! empty( $postdata['city'] ) ) echo esc_attr($postdata['dokan_address']); ?>" required="required" />
</p>

Woocommerce wc_create_new_customer override on checkout

I am using the guest checkout and have enabled "Automatically generate username from customer email" and "Automatically generate customer password", also I created a hidden input
<input class="input-checkbox" id="createaccount" <?php checked( ( true === $checkout->get_value( 'createaccount' ) || ( true === apply_filters( 'woocommerce_create_account_default_checked', false ) ) ), true) ?> type="checkbox" name="createaccount" value="1" /> <label for="createaccount" class="checkbox"><?php _e( 'Create an account?', 'woocommerce' ); ?></label> , which helps automatically create a user on checkout so customers didn't know that a user has been generated by their email. But if the same user, with the same email tries to fill the same email on the checkout field, receives the message: "An account is already registered with your email address. Please login." , which comes from wc_create_new_customer function inside the /woocommerce/includes/class-wc-checkout.php.
I would like to override wc_create_new_customer function and return the $customer_id for the existing user instead of firing and error for already registered account. Tried hooks and filters, but none of them works. Any help?
Thanks in advance!

BuddyPress Xprofile fields to display on "wordpress user edit admin panel"

I am building a buddypress/bbpress, website with xprofile registration fields. I am using New User Approve plugin to approve each users manually since we need to check information of each user before they get activated.
Problem here is, I am unable to check/view the xprofile field values in Wordpress user edit admin panel. All I have is the username change password, changing roles etc. I want the admin panel to display the extra information of the registered user so that I can check the info and approve . Anyone can help me out to solve this problem.
Might be similar to this.. haven't tried the code though....
Replace the key value 'xprofile_key_birthday' with actual xprofile keys in Buddypress DB.
Note: This code only displays the values on the edit screen and doesn't insert or update anything.
<?php
add_action( 'show_user_profile', 'showmy_extra_profile_fields' );
add_action( 'edit_user_profile', 'showmy_extra_profile_fields' );
function showmy_extra_profile_fields( $user ) { ?>
<h3>Extra profile information</h3>
<table class="form-table">
<tr>
<th><label>xprofile_key_birthday</label></th>
<td>
<?php
if( function_exists( 'xprofile_get_field_data' ) ) {
$xprofile_value = xprofile_get_field_data('xprofile_key_birthday', $user->ID );
}
else {
$xprofile_value = '';
}
?>
<input type="text" name="xprofile_key_birthday" id="xprofile_key_birthday" value="<?php echo esc_attr( $xprofile_value ); ?>" class="regular-text" readonly />
</td>
</tr>
</table>
<?php
}
?>
I use the free Wangguard plugin on my BuddyPress/bbPress website. All I need to do is click on "Users" in the Wangguard menu on Wordpress dashboard sidebar and then click on "BP Profile" under the member username column. I can view and even edit the member profile from there. Hope it helps.

Wordpress: Page template with default fields

WordPress 3.2.1
I'm creating separate page templates, however, there are some page templates that should have default custom fields. That is, if someone created a new page of template type "Contact Us", it should by default have custom fields:
Success Message
Email To
Phone Number
etc.
Right now, the only way I can think of knocking this out is by having the admin add those custom fields to the page, and then fill them in. However, this isn't the best method for basically giving an admin a "turn-key" type of feature, i.e., they create a page with a specific template and just fill in the fields.
Thanks guys!
The following will add 1 extra meta box to your (insert-edit) page.
In it you can add custom fields to save.
It does not switch depending on the selected template.
I would recomend using javascript to show/hide fields to do this. Based on ID of the <p>
If you get the meta box working with ALL possible fields you can show I'm willing to help with the javascript to hide and show based on the template.
GL
<?php
add_action( 'add_meta_boxes', 'carrousel_build' );
function carrousel_build()
{
add_meta_box('carrousel', 'Carrousel opties', 'carrousel_options', 'page',/*show on 'pages'*/ 'normal', 'high');
}
//this will add a meta box with custom fields
function carrousel_options ($post)
{ ?>
<p>
Description
</p>
<p id="field1_container">
<label for="field1">Custom field 1</label>
<br/>
<input type="text" id="field1" name="field1" value="<?php echo get_post_meta($post->ID, 'field1', true) ?>" size="25" />
</p>
<p id="field2_container">
<label for="field2">Custom field 2</label>
<br/>
<input type="text" id="field2" name="field2" value="<?php echo get_post_meta($post->ID, 'field2', true) ?>" size="25" />
</p>
<?php }
//save the values of the meta box
add_action( 'save_post', 'post_save' );
function post_save($post_id)
{
// Check permissions
if (isset ($_POST['post_type']) && 'carrousel' == $_POST['post_type'] && !current_user_can( 'edit_page', $post_id ))
{
return;
}
if (isset($_POST['field1'])) {
$subtitle = $_POST['field1'];
update_post_meta($post_id, 'field1', $subtitle);
}
if (isset($_POST['field2']))
{
$link = $_POST['field2'];
update_post_meta($post_id, 'field2', $link);
}
}

Resources