I need to create a payment form with redirect to Chronopay payment gate on wordpress. I try to make it with CF7 plugin with database extension.
How can I do next things:
1. Add unique ID and payment status to CF7 database strings. (I have added 2 fields to database and tried to change them with hook on wpcf7_before_send_mail).
function order_set_id($f) {
global $wpdb;
global $table_prefix;
$submit_time = $f->submit_time;
$title = $f->title;
if ('Taxy pick up' == $title ) {
$sql = "SELECT MAX(order_id) as mid FROM `wp_cf7dbplugin_submits`";
$var = $wpdb->get_results($wpdb->prepare($sql));
$neworder_id = $var[0]->mid;
$wpdb->update( 'wp_cf7dbplugin_submits',
array( 'order_id' => 0, 'order_payment' => 0 ),
array( 'submit_time' => $submit_time ),
array( '%s', '%d' ),
array( '%d' )
);
}}
add_action( 'wpcf7_before_send_mail', 'order_set_id');
But it doesn't work.
I need to display a hidden form as payment invoice after submittin a form. How can I do it?
How can I block sending email messages in Contact Form 7?
In the nearly past I wanted something similar. Found this two methods:
http://runastartup.com/integrate-paypal-button-with-contact-form-in-wordpress/
http://www.gobdg.com/blog/code-library/donation-form-using-contact-form-7-paypal/
Idea is on hold for now, but asap I will have free time, will decide which method to use.
Good luck! :)
Related
I'm writing a custom wordpress plugin to manage user registrations. I have created two custom roles, that are named customer and merchant, the merchant role users are created from the admin of the site. I need to assig to each merchant account a custom meta to identify it, but from the wp user admin panel this is not possible.
In the registration form for customers I have a field that will be saved inside the user meta table and will contain a code that will be selected from the user from a dropdown menù and is used to identify the merchants.
<?php
wp_insert_user(
array(
'meta_input' => array('merchant_code' => '001'), // this code is passed from the frontend
'role' => 'customer'
)
);
?>
I'm not sure if is possible with a flter or an hook, but what I need is to check for this code when the merchant users will login, this because I will show to each merchant a different customers list. Any suggestion about?
You can use the user_register action hook to intercept the user registration.
We then generate a pseudo random identifier based on the user registration timestamp and the user id.
We retrieve the userdata through get_userdata() and update them through wp_update_user() (which fetch his arguments from wp_insert_user()).
The following is untested but should work:
<?php
add_action( 'user_register', function ( $user_id ) {
$user = get_userdata( $user_id );
$pseudo_random_identifier = null;
$pseudo_random_identifier .= $user_id;
$pseudo_random_identifier .= str_replace( array( '-', ' ', ':', ), '', $user->user_registered );
$pseudo_random_identifier .= sanitize_title_with_dashes( $pseudo_random_identifier );
$userdata = array (
'ID' => $user_id,
'meta_input' => array(
'merchant_code' => $pseudo_random_identifier,
),
);
wp_update_user( $userdata );
} );
Tho for your information, you can change the user role too.
Can anyone help/have some ideas on how to prepopulate gravityforms fields based on users latest entry of the same form.
I've users, who will "register" to an event every year and fill the same form, so it would be nice to have the same fields already filled and if the client wants, they can refill some of the changed fields themselves.
So far I've found some info from gravityforms docs myself, but this code seems only to be prepopulating only one field? Still haven't gotten it to work.
The code ->
add_filter( 'gform_field_value_previous_value', 'populate_previous_value', 10, 2 );
function populate_previous_value( $value, $field ) {
$entries = GFAPI::get_entries(
$field->formId,
array(
'field_filters' => array(
array(
'key' => 'created_by',
'value' => get_current_user_id(),
),
),
),
array(),
array( 'page_size' => 1 )
);
return rgars( $entries, '0/' . $field->id );
}
I assume, the value between the rgars apostrophes aka the field id needs to be filled?
If anyone else is wondering/struggling to solve this issue - I've come to the realization that the best and easiest way to pre-populate fields values based on logged in user is through gravity forms merge tags.
Best way to use merge tags based on logged in user is next:
{user:[meta_tag}
You can use all the meta fields available, also the billing_address and billing_postcode and so on, as long as you include 'user:' before.
So the fields get populated based on logged in users meta fields. The merge tags need to be placed to form field->advanced->under default value.
For example if you need logged in users first name and last name to be populated you would add {user:first_name} to the first name default value field and {user:last_name} to the last name value field.
I am building a WP site with membership and forum plugins.
Upon registration people select their username, however the default display name is their First + Last name. This is not ideal, I need the display name to be the same as username. I added this code but doesn't seem to work:
function change_display_name( $user_id ) {
$info = get_userdata( $user_id );
$args = array(
‘ID’ => $user_id,
‘display_name’ => $info->username
);
wp_update_user( $args );
}
add_action(‘user_register’,’change_display_name’);
Any help greatly appreciated!
You can use
wp_insert_user to register a user.
See this link
How can I store the values from a WPForm in WordPress to a MySQL database?When we use WPForms where I have to add PHP part to store data? Can we store form data to tables when we are using free version of WPForms without buying it?
If you are using WP Forms Lite you can't do this directly, either you'll need to upgrade to PRO version or build your own custom save actions.
If you decide to go with your own custom version, some details below on how to intersect form submission on WP Forms.
WPForms has some actions you can use to do you own custom actions after form submission:
wpforms_process_complete
do_action( 'wpforms_process_complete', $this->fields, $entry, $form_data, $entry_id );
By using on your own template or plugin the wordpress hook add_action for any of the events described, you are able to get form data and do the handling you need.
Reference for wordpress add_action can be seen on the official documentation.
https://developer.wordpress.org/reference/functions/add_action/
Did a quick snippet that will help you get started:
add_action("wpforms_process_complete", 'function_save_custom_form_data');
function function_save_custom_form_data($params) {
foreach($params as $idx=>$item) {
$field_name = $item['name'];
$fiel_value = $item['value'];
// Do whatever you need
}
return true;
}
Please let me know if you need any further details.
WPForms store all form data in two tables within the native WordPress database. They are:
wp_wpforms_entries: In this table, the field values for entries are stored.
wp_wpforms_entry_meta: This table contains meta information about your entries such as IDs associated and the date that entries were submitted.
After publishing the form, make sure to add a form entry, so we can access the entry from your WordPress dashboard. Additionally, in your form builder, go to Settings » General and make sure that entry storing in WordPress is not disabled.
Create custom tables for example wpforms_entries and wpforms_entry_meta in your database to store form data. Use the provided action hook wpforms_process_complete to store the form entries.
add_action( 'wpforms_process_complete', 'process_entry', 5, 4 );
function process_entry( $form_fields, $entry, $form_data, $entry_id ) {
global $wpdb;
$form_id = $form_data['id'];
$entry_data = array(
'form_id' => $form_id,
'status' => 'publish',
'referer' => $_SERVER['HTTP_REFERER'],
'date_created' => current_time( 'mysql' )
);
// Insert into wpforms_entries custom table.
$success = $wpdb->insert( $wpdb->prefix . 'wpforms_entries', $entry_data );
$entry_id = $wpdb->insert_id;
// Create meta data.
if ( $entry_id ) {
foreach ( $form_fields as $field ) {
$field = apply_filters( 'wpforms_process_entry_field', $field, $form_data, $entry_id );
if ( isset( $field['value'] ) && '' !== $field['value'] ) {
$field_value = is_array( $field['value'] ) ? serialize( $field['value'] ) : $field['value'];
$entry_metadata = array(
'entry_id' => $entry_id,
'meta_key' => $field['name'],
'meta_value' => $field_value,
);
// Insert entry meta.
$wpdb->insert( $wpdb->prefix . 'wpforms_entrymeta', $entry_metadata );
}
}
}
}
Refrence: https://github.com/sanzeeb3/entries-for-wpforms/blob/master/includes/functions-wpfe-core.php#L59
Alternatively, the plugin itself is available: https://wordpress.org/plugins/entries-for-wpforms/
Free version of WPForms does not save the entry details captured in form. Therefore, you will need to write custom code to save the values in your custom DB table and then display them.
Below hook of WPForms can be used for saving data being entered in WPForms
/*hook to save entries coming from WPforms into database*/
add_action( 'wpforms_process_entry_save', array( $this, 'ank_wpforms_save_entries' ), 10, 4 );
public function ank_wpforms_save_entries( $fields, $entry, $form_id, $form_data ) {
//no need to sanitize data coming from WPForms as it is being sanitized in WPForms plugin before this hook using
//wpforms_process_validate_{$field_type} in class-process.php
$data = array();
$data['form_id'] = $form_id;
$data['entry_details'] = $fields;
//additional sanity checks are also performed while json encoding in "add" before adding in database
ank_wpforms_entry()->get_class_instance( 'entry-db' )->add( $data );
}
Alternatively , You can use this free plugin to save entries coming from WPForms into wordpress database and then display them in Wordpress Dashboard - https://wordpress.org/plugins/add-entries-functionality-to-wpforms/
Tried to be as specific as possible in the title. Essentially I have a real estate site that I am working on that has property listings. The property listing is a custom post type and there are several other custom post types (each with their own custom fields) attached to it.
Each property has an agent (custom post type) attached to it with custom fields such as email, facebook, phone number, etc.
I need to dynamically pre-populate a hidden field on Gravity Forms with the agent email (which is NOT the same as the author email) so that I can send an email to that address.
I have tried the following with no luck because I'm sure something is missing to call the custom field from the Agent custom post type, but I'm not sure how. This is what I'm working with so far:
add_filter('gform_field_value_agentemail', 'populate_post_agent_email');
function populate_post_agent_email($value){
global $post;
$agents_email = get_post_meta($post->ID, 'agent_email', true);
return $agents_email;
}
I have added the parameter name "agentemail" to the gravity form field. If anyone knows what I am missing to be able to get this field (or any field from the agent custom post) into this form, it would be much appreciated.
Thanks.
Here's How I Populated my GravityForms Dropdown using a little code that I found created by Joshua David Nelson, josh#joshuadnelson.com
With a few minor modifications I was able to get the proper output to the dropdown box (was looking for user email addresses instead of user nicenames, but you can modify this script to output anything you want with a few small changes to the query args)
// Gravity Forms User Populate, update the '1' to the ID of your form
add_filter( 'gform_pre_render_1', 'populate_user_email_list' );
function populate_user_email_list( $form ){
// Add filter to fields, populate the list
foreach( $form['fields'] as &$field ) {
// If the field is not a dropdown and not the specific class, move onto the next one
// This acts as a quick means to filter arguments until we find the one we want
if( $field['type'] !== 'select' || strpos($field['cssClass'], 'your-field-class') === false )
continue;
// The first, "select" option
$choices = array( array( 'text' => 'Just Send it to the Default Email', 'value' => 'me#mysite.com' ) );
// Collect user information
// prepare arguments
$args = array(
// order results by user_nicename
'orderby' => 'user_email',
// Return the fields we desire
'fields' => array( 'id', 'display_name', 'user_email' ),
);
// Create the WP_User_Query object
$wp_user_query = new WP_User_Query( $args );
// Get the results
$users = $wp_user_query->get_results();
//print_r( $users );
// Check for results
if ( !empty( $users ) ) {
foreach ( $users as $user ){
// Make sure the user has an email address, safeguard against users can be imported without email addresses
// Also, make sure the user is at least able to edit posts (i.e., not a subscriber). Look at: http://codex.wordpress.org/Roles_and_Capabilities for more ideas
if( !empty( $user->user_email ) && user_can( $user->id, 'edit_posts' ) ) {
// add users to select options
$choices[] = array(
'text' => $user->user_email,
'value' => $user->id,
);
}
}
}
$field['choices'] = $choices;
}
return $form;
}
/* end of populate advisors for dropdown field */
To get this to work all you should need to do is add the above code to your functions.php file, add the 'ID' (into the add_filter reference) of the GravityForm that you're looking to alter and add the 'Class' of your dropdown field (where is says 'your-field-class').
If you have any questions about the above code, let me know.
Adam
I'm working on this one right now - I was able to pass the values from one page to another appending the information onto the end of the url -
ex. http://www.your-website.com/?agentemail=agent#email.com
For this to work you have to check the 'Allow this field to be populated Conditionally' when editing the field in question.
It's not the be-all-end-all for me (I'd like to generate this on page load, rather than attaching it to a button, but it's a start. I'll comment again when I have the filtering worked out.
Adam