Wordpress New Registration Form with Radio Button - wordpress

I'm a Wordpress newbie and I am stumped. I've tried to Google it for help, looking for plugins. I haven't been successful.
I'd like to create 2 choices for the user: Member or Vendor, and based on their selection, it sends an email when they finish upon registration.
So if I select Member, then it sends an email to member#gmail.com or if they select vendor,vendor#gmail.com will be submitted.
Can somebody help me please?

There will be a registration form in which add this selection
//form starts
//other fields
<input type = "radio" name = "user_role" value = "Member">Member</input>
<input type = "radio" name = "user_role" value = "Vendor">Vendor</input>
//submit
//on submit
if(isset($_POST['user_role'])){
//Here check value selected from both choices
if($_POST['user_role'] == "Member"){
$email_id = "member#gmail.com";
}
else{
$email_id = "vendor#gmail.com";
}
//send email
}

Related

Custom validation Ninja form with error handle

I'm using Ninja Form plugin in my WordPress installation.
My form has 3 input text fields.
I need, after pressing the submit button, to validate one of this input by checking if the entered value exists in a custom table in my database.
If the value doesn't already exists nothing should happen (Ninja Form save the form), if it exists I need to add a Ninja Form error and let the user change the input in order to save the form with a new value.
How can I hook the submit action? How can I get in this hook the input value I need? How can I add a Ninja Form error if the value exists in order to prevent the form save?
You can do this using the ninja_forms_submit_data hook. There you can access the value of a field using its id through the variable $form_data. When adding an error message for the field to $form_data['errors'] the form will not be saved.
Like this (in functions.php):
add_filter('ninja_forms_submit_data', 'custom_ninja_forms_submit_data');
function custom_ninja_forms_submit_data($form_data)
{
$field_id = 2;
$field_value = $form_data['fields'][$field_id]['value'];
$exists = true; // Check your database if $field_value exists
if($exists)
{
$form_data['errors']['fields'][$field_id] = 'Value already exists';
}
return $form_data;
}

Contact form 7 - Manipulate response messages

I have a contact form 7 form where a user can input his/her e-mail address and a coupon code. If the e-mail-address or code cannot be found in the database, distinct error messages should be displayed to the user after the submit.
I use the wpcf7_before_send_mail hook to find out if the e-mail address / coupon code are valid:
add_action('wpcf7_before_send_mail', 'your_wpcf7_mail_sent_function');
function your_wpcf7_mail_sent_function($contact_form)
{
//get user e-mail and coupon nr from database
$entry = select("SELECT e-mail, coupon_nr FROM {$wpdb->prefix} woocommerce_coupons WHERE coupon_nr = '{$couponNr}'");
if (is_null($entry[0]->e-mail)
{
$skipMail = true;
$status = "USER_NOT_FOUND";
}
else if(is_null($entry[0]->coupon_nr)
{
$skipMail = true;
$status = "COUPON_INVALID";
}
else
{
$status = "OK";
}
}
What I want to achieve is to display an appropriate error message to the user depending on the status. E.g. if status is "USER_NOT_FOUND", a different message should be displayed as if the status was "COUPON_INVALID".
Any help is very appreciated.

Mailchimp API 2.0 using listSubscribe() multipe times

I'm making an integration of Shopp and Mailchimp for a client on a WordPress-based site. The checkout page has input for multiple email addresses, all of which should be added to MailChimp via the API. I've had success with listSubscribe() using the MCAPI.php wrapper in getting the first email to work. Can the listSubscribe() be re-used in the same PHP function that runs as checkout is processed?
Here's the code I have at the moment:
/* include MailChimp API on checkout init */
add_action('shopp_order_success', 'opc_mc_checkout');
function opc_mc_checkout () {
// do stuff
require_once 'MCAPI.class.php';
$apikey='redacted'; // Enter your API key
$api = new MCAPI($apikey);
$retval = $api->lists();
$listid='redacted'; // Enter list Id here
$email=shopp('purchase.email', 'return=true'); // Enter subscriber email address
$name=shopp('purchase.firstname', 'return=true'); // Enter subscriber first name
$lname=shopp('purchase.lastname', 'return=true'); // Enter subscriber last name
// By default this sends a confirmation email - you will not see new members
// until the link contained in it is clicked!
$merge_vars = array('FNAME' => $name, 'LNAME' => $lname);
if($api->listSubscribe($listid, $email,$merge_vars) === true) {
}
/* teacher extra emails */
$apikey='redacted'; // Enter your API key
$api = new MCAPI($apikey);
$retval = $api->lists();
$listid='redacted'; // Enter list Id here
$teacher_1_email=shopp('purchase.data', 'name=Teacher 1 Email&return=true'); // Enter subscriber email //$teacher_1_email=$_POST['Teacher 1 Email']; // Enter subscriber email
$teacher_1_name=shopp('purchase.firstname', 'return=true'); // Enter subscriber first name
$teacher_1_lname=shopp('purchase.lastname', 'return=true'); // Enter subscriber last name
$merge_vars = array('FNAME' => $teacher_1_name, 'LNAME' => $teacher_1_lname);
if($api->listSubscribe($listid, $teacher_1_email,$merge_vars) === true) {
}
I've searched Google and the API documentation up and down without luck. Ay help would be greatly appreciated!
Thanks!

How to change Sender's Email in WooCommerce?

WooCommerce -> Settings -> EmailS -> the first two options, "FROM: Name, FROM: Email", are the Sender's email and name. When an order is placed a notification email is sent to both Shop Manager and Customer from the same Sender's email and name (which we set from admin dashboard).
When Customer replies to that email, he basically replies to Shop Manager and it works fine.
But Shop Manager receives the notification email from his (given) email address, in actually there would be client's email.
P.S: I want that Shop Manager gets the email from the customer's billing email and customer gets it from Shop Manager's given email.
https://wordpress.org/plugins/woocommerce/
The only way I can think of to achieve this is to programmatically generate the Shop Manager notification email using one of the system action hooks. Since there is only one field in the "from" settings, it will be used (by default) for all the outbound messages.
That said, check out the Code Snippets plugin at https://wordpress.org/plugins/code-snippets/. You can put some code here (and it will be saved to the DB, and included the system code at runtime) that could generate this programmatic email when, say, a new order is generated.
Hope it helps.
After going through your question it made sense that for a shop owner it needs to be like the mail should have sent from address as the client's email address, so that he can reply to each order in a single email thread.
//filter for the "mail from" email address which is set in WooCommerce Settings Email Tab-> Email Sender Options -> "From" Email Address which is generally set to the shop admin email address or a support team email address.
add_filter('wp_mail_from', 'wdm_sent_from_email', 99, 1);
//function which will change the mail from email address to the the Customer's billing address if the mail this filter is running which sending mail to the admin.
function wdm_sent_from_email( $sent_from = '' ) {
//check whether our custom parameter is set or not.
if ( isset($_POST['wdm_sent_to_admin']) ) {
//check whether the mail is sent to the admin and other recieptent other than customer
if ( $_POST['wdm_sent_to_admin'] ) {
//set it to the customer's billing email
$sent_from = $_POST['billing_email'];
//set this parameter back to false
$_POST['wdm_sent_to_admin'] == false;
}
}
return $sent_from;
}
//filter for email from name
add_filter('wp_mail_from_name', 'wdm_sent_from_name', 99, 1);
function wdm_sent_from_name( $sent_from_name = '' ) {
//check whether our custom parameter is set or not.
if ( isset($_POST['wdm_sent_to_admin_from_name']) ) {
//check whether the mail is sent to the admin and other recieptent other than customer
if ( $_POST['wdm_sent_to_admin_from_name'] ) {
//set sent mail from name eg. "Website-Name customer"
$sent_from_name = wp_specialchars_decode(esc_html(get_option('woocommerce_email_from_name')), ENT_QUOTES) . " customer";
//set this parameter back to false
$_POST['wdm_sent_to_admin_from_name'] = false;
}
}
return $sent_from_name;
}
//action were we will set and the parameter to indicate whether the mail is sent to admin or customers.
add_action('woocommerce_email_header', 'wdm_header_function', 99, 1);
function wdm_header_function( $email_heading ) {
if ( $email_heading == 'New customer order' ) {
//parameter to indicate whether to change the from email in the mail.
$_POST['wdm_sent_to_admin'] = true;
//parameter to indicate whether to change the from name in the mail.
$_POST['wdm_sent_to_admin_from_name'] = true;
//Just to indicate in mail sent to admin that the sent from email is set in code.
echo "<b>Its Because you have chosen to have this email sent from Customer's Email id.</b>";
} else {
//parameter to indicate whether to change the from email in the mail.
$_POST['wdm_sent_to_admin'] = false;
//parameter to indicate whether to change the from name in the mail.
$_POST['wdm_sent_to_admin_from_name'] = false;
}
}
Note : This might give you and alert message while viewing the message at your side only saying "This message may not have been sent by: (your customer's billing address) " as this is not really sent by a customer to you.
Try out the above code and lemme know whether it works for you and accomplishes your purpose.
I think you can also use wordpress hooks for that:
// Function to change email address
function wpb_sender_email( $original_email_address ) {
return 'tim.smith#example.com';
}
// Function to change sender name
function wpb_sender_name( $original_email_from ) {
return 'Tim Smith';
}
// Hooking up our functions to WordPress filters
add_filter( 'wp_mail_from', 'wpb_sender_email' );
add_filter( 'wp_mail_from_name', 'wpb_sender_name' );

Wordpress Login if user_meta (confirmFlag = 1)

I created an extra user meta field (confirmFlag = 0) when new user register on my page.
They get a email to confirm their registration. They click on the link and on the page the user meta field turns into 1 (confirmFlag = 1).
Now, the thing is, how can I make user only login if the user meta field is 1 (confirmFlag = 1).
If ths field is 1 everything is ok and the user gets to the dashboard.
If the field is still 0 the login should fail and a message should say that the user have to confirm the registration by the link in the email.
Any suggestion?
Appreciate your help
<?php global $current_user;
get_currentuserinfo(); //wordpress global variable to fetch logged in user info
$userID = $current_user->ID; //logged in user's ID
$havemeta = get_user_meta($userID,'test',true); //stores the value of logged in user's meta data for 'test'.
if ($havemeta)
{
echo 'your stuff';
}
else {
echo "No";
}
or Try this plugin
http://wordpress.org/extend/plugins/user-meta/

Resources