75%off on HostGator – Black Friday Fire Sale

75%off on HostGator – Black Friday Fire Sale

Hey Friends,

Very much excited to tell you about this Black Friday Sale. I am waiting from may days for Black friday sale at hostgator.com

Black Friday has officially begun! They are starting things off with a FIRE SALE, 75% off ALL new hosting plans. This sale ends at 3PM CST, but there will be more Fire Sales throughout the day. Everything is live right now at http://www.hostgator.com/ though the related coupon code for this initial Fire Sale is BFFIRE2. Happy Black Friday, everyone. Stay safe out there!

75% off Black Friday Sale at Hostgator

This sale will live from Black Friday through Cyber Monday… Starting at $1.24/month

Black Friday pricing of 75% is now active. These are the lowest prices for web hosting this year; take advantage of these deep discounts!

Sale is ended. Please check Cyber Monday Sale.

We have new offer for you on this Christmas. Click here to grab this offer.

Free dot com domain and 10% off on hosting

Free dot com domain and 10% off on hosting

Easy way to Change Woocommerce default user Role.

Easy way to Change Woocommerce default user Role.

Hello buddy,

I want to share something with you about Easy way to Change Woocommerce default user Role customer to something you need or like. I was working on LMS project so wrote down few lines of code that I want to share with you. May it help you.

Woocommerce allows WordPress user registration at checkout and my account page. It creates user by default role as customer. But for purpose of your project,sometime you may need other role other than customer. As in LMS project, I wanted user to have student role, who registers at checkout page. So not need to worry for that. Woocommerce Gives a control over it using via a filter `woocommerce_new_customer_data`.

In \wp-content\plugins\woocommerce\includes\wc-customer-functions.php : line 102

<?php
$new_customer_data = apply_filters( 'woocommerce_new_customer_data', array(
    'user_login' => $username,
    'user_pass'  => $password,
    'user_email' => $email,
    'role'       => 'customer'
) ); ?>

In above lines extracted from Woocommerce, woocommerce_new_customer_data is filter applied over $new_customer_data variable. Still user is not registered, so you can deal with users data as you wish, wp user get created.

You can filter User Role by changing value in Array ($new_customer_data) provided by woocommerce_new_customer_data filter. You must use add_filter action in you theme’s function.php file or your plugin file. Write your own function like my_new_customer_data().

Dafault format of filter is as below.

<?php add_filter( $tag, $function_to_add, $priority, $accepted_args ); ?> 

You have to pass minimum 2 parameters to add_filter action. i.e. $tag, $function_to_add

<?php add_filter( 'woocommerce_new_customer_data', 'my_new_customer_data'); ?>

In your function just have to replace value of key index which is ‘role’. You can directly specify user role like option one as shown below or You can get default user role from WordPress default user role option(Which is in general settings) like option two.

Option one:

<?php $new_customer_data['role'] = 'student'; ?>

Option two:

<?php $new_customer_data['role'] = get_option( 'default_role' ); ?>

Hence finally you just have to add below lines of code to your theme or plugin. Enjoy WordPress and Woocommerce with your project. Happy coding. 🙂  🙂  🙂

<?php
function my_new_customer_data($new_customer_data){
 $new_customer_data['role'] = get_option( 'default_role' );
 return $new_customer_data;
}
add_filter( 'woocommerce_new_customer_data', 'my_new_customer_data');
?>