Wordpress Help (WPForms + PayPal Workflow) - wordpress

CONTEXT:
I’ve used the WPForms plugin in Wordpress to create a custom donation form for my client. The client wants to accept donations via PayPal.
PROBLEM:
WPForms has a PayPal add-on feature but it costs $200.
QUESTION
To avoid paying $200 for the expensive plugin, how can I manually direct/post the WPForm data entered by the user (name, email, address, donation amount, and employment info) to PayPal?

In the example code you’ll see below, we’re first checking the form ID to make sure it matches the form that’s being targeted. Then we’re checking a specific field (by the field ID) to see if it’s empty.
Just remember to change the form ID from 5 to match your form ID and change the '4' to match your field ID.
function wpf_dev_process( $fields, $entry, $form_data ) {
// Optional, you can limit to specific forms. Below, we restrict output to
// form #5.
if ( absint( $form_data['id'] ) !== 5 ) {
return $fields;
}
// check the field ID 4 to see if it's empty and if it is, run the error
if(empty($fields[4]['value']))
{
// Add to global errors. This will stop form entry from being saved to the database.
// Uncomment the line below if you need to display the error above the form.
// wpforms()->process->errors[ $form_data['id'] ]['header'] = esc_html__( 'Some error occurred.', 'plugin-domain' );
// Check the field ID 4 and show error message at the top of form and under the specific field
wpforms()->process->errors[ $form_data['id'] ] [ '4' ] = esc_html__( 'Some error occurred.', 'plugin-domain' );
// Add additional logic (what to do if error is not displayed)
}
}
add_action( 'wpforms_process', 'wpf_dev_process', 10, 3 );

Related

Wordpress - Send email on Post meta value change

I want to accomplice the following. I want to automatically send an email on post publish/update when a certain post field value has changed.
In a post
A ACF field that has 4 options, lets say [ 'draft', 'ready for group1', 'ready for group 2', 'ready']
If this field gets changed on post update send email to "this" email address.
I think I need to know 2 things for this.
- How and where (what action) do I need to insert custom code on post publish/update
- How to compare new post data to old state (and is this possible/availible in the action above)
You can hook onto acf/save_post for this purpose. Read the documentation here:
https://www.advancedcustomfields.com/resources/acf-save_post/
Since you want the callback to fire before the values are stored, in order to compare the old value against the new one, keep in mind to add a priority of less than 10. Assuming the field with 4 options has the field key field_4afd4af14415f:
function on_acf_post_save($post_id) {
$post_type = get_post_type($post_id);
if ($post_type === 'your-post-type') {
$old_val = get_field('field_4afd4af14415f', $post_id);
$new_val = $_POST['acf']['field_4afd4af14415f'];
if ($old_val != $new_val) {
// Send desired mail in here:
// wp_mail(...);
}
}
}
add_action('acf/save_post', 'on_acf_post_save', 5, 1); // priority = 5
If your ACF field isn't at the top level, but inside a Group or Repeater, you will have to adapt the code reading from the $_POST['acf'] and get_field() result.

wordpress add payment system. Where to handle form

I wanna to add payment to wordpress . Payment system called PayBox. https://paybox.money/docs/ru/pay-in/3.3#tag/Inicializaciya-cherez-brauzer-polzovatelya/paths/~1payment.php/get . I trying to create form and send data with post method to php file and send request to payment with code below.
<?php
$request = [
'pg_merchant_id'=> 111,
'pg_amount' => 25,
'pg_salt' => 'some_random_string',
'pg_order_id'=>'123',
'pg_description' => 'Описание заказа',
'pg_result_url' => 'https://example.com'
];
// $request['pg_testing_mode'] = 1; //add this parameter to request for testing payments
//if you pass any of your parameters, which you want to get back after the payment, then add them. For example:
// $request['client_name'] = 'My Name';
// $request['client_address'] = 'Earth Planet';
//generate a signature and add it to the array
ksort($request); //sort alphabetically
array_unshift($request, 'payment.php');
array_push($request, 'secret_key'); //add your secret key (you can take it in your personal cabinet on paybox system)
$request['pg_sig'] = md5(implode(';', $request));
unset($request[0], $request[1]);
$query = http_build_query($request);
//redirect a customer to payment page
header('Location:http://core.local/payment.php?'.$query);
But problem is . Where can I handle this code? I dont know how to do this in wp. Form created with page builder .
You need to find out with your page builder that creates the form if they are able to handle hooks. See if there's a function you can hook into when the form is processed.
Generally this would go in your functions.php file of your theme (or a child theme if you're using a ready-made theme).

A Webhook contact form for Discord in wordpress

So I'll start out by saying, that I am a bit new to this.
So I have this website I'm currently making. It's a guild website for World of Warcraft, and we want to be able to have new people being able to apply for membership.
Making the contact form is easy enough through plugins, but this is in theory what I wish to make:
A contact form where when filled in, the application form will push a notification to a webhook set in Discord where when new applicants happen, a message in a channel will be made, notifying the leaders about it.
Do I need to create a plugin myself, or is there any plugin that can offer this functionality?
I had the same needs, after sometime i found a way to do it.
Its actually very simple with WPForms.
WPForms has hooks so you can easily track forms submitions with the wpforms_process_complete hook. This hook allows you to track ALL WPForms sumbission. But maybe you'd like to have different forms. If you wish to track only a specific form, you can add the form id to the end of the hook name.
In my case i had many different forms which are being handled in various different ways, so i had to split them. When a form is being created in WPForms, it receives an ID so does the fields of the named form.
In my case after my form was created it had the following id :
The hook function.
As explained on the Discord Webhook page, Webhooks are a low-effort way to post messages to channels in Discord. They do not require a bot user or authentication to use. The endpoint supports both JSON and form data bodies. In my case i went for JSON.
As explained here you just need to use one of the the content file or embeds field. On this example i will just send a message, so i'll be using the content field.
Once the above instructions applied, you should end up with something close to the following function :
if ( ! function_exists( 'discord_form_submission' ) ) :
/**
* This will fire at the very end of a (successful) form entry.
*
* #link https://wpforms.com/developers/wpforms_process_complete/
*
* #param array $fields Sanitized entry field values/properties.
* #param array $entry Original $_POST global.
* #param array $form_data Form data and settings.
* #param int $entry_id Entry ID. Will return 0 if entry storage is disabled or using WPForms Lite.
*/
function discord_form_submission( $fields, $entry, $form_data, $entry_id )
{
// You have to replace this url by your discord webhook.
$endpoint = 'https://discord.com/api/webhooks/{webhook.id}/{webhook.token}';
// This is the content you can put anything you wish.
// In my case i needed the Name, Class, and the Level of the players.
$content = "**Name :** " . $fields[1]['value'] . PHP_EOL;
$content .= "**Class :** " . $fields[2]['value'] . PHP_EOL;
$content .= "**Level :** " . $fields[3]['value'] . PHP_EOL;
// WP has its own tool to send remote POST request, better use it.
wp_remote_post( $endpoint , [
'headers' => [
'Content-Type' => 'application/json; charset=utf-8'
],
'body' => wp_json_encode([ // Same for the JSON encode.
'content' => $content,
]),
'method' => 'POST',
'data_format' => 'body'
]);
}
endif;
This function must be added in the functions.php file of your theme.
Last but not least, with the help of the WP add_action Function you need to hook up with the wpforms_process_complete hook. In my case since i want to only hook up to the form with the id 1862 i have added the id at the end of the hook which gives us the following code :
add_action( 'wpforms_process_complete_1862', 'discord_form_submission', 10, 4 );
This code must be added in the functions.php file of your theme after our newly added function.

Gravity forms: Authorize.net Invoice number

I was wondering If you knew how to add an invoice code to the forms in Authorize.net.
I check the authorize.net feed settings but they do not ask for an invoice code.Then, I started to do some research and found the hook gform_authorizenet_save_entry_id that could be used to create that invoice code.
The problem comes that there is no documentation about this hook. It was only mentioned as one of the updates. So, I'm creating a hidden field with an {entry_id} as a default value and trying to find a way to pass it as an Invoice Number.
Any help would be appreciated. Thanks :)
Update:
I was able to add a transaction code to the form using the following Snippet
//Adding the transaction code
add_filter( 'gform_authorizenet_transaction_pre_capture', 'set_invoice_number', 10, 5 );
function set_invoice_number( $transaction, $form_data, $config, $form, $entry ) {
if ( $form['id'] == 6 ) {
// your submission ID format to be inserted into the hidden field
$SubmissionID = 'RW-' . $entry['id'];
$transaction->invoice_num = $SubmissionID;
}
return $transaction;
}
I got the invoice number to become "RW-" but the $entry['id'] is not printing anything
You can assign an invoice number using an input field by adding this code to your theme's functions.php file:
add_filter('gform_authorizenet_transaction_pre_capture', 'set_invoice_number', 10, 4);
function set_invoice_number($transaction, $form_data, $config, $form)
{
$transaction->invoice_num = rgpost('input_YOUR INPUT FIELD NUMBER HERE');
}
If the input field is the hidden field containing the form's entry id that should accomplish what you're wanting.
I use the following code to append the "Form Name" to the invoice number passed to Authorize.net. I believe that the previous answer would work if the first field you create in each form was the "Invoice Number" field, but if you add the field later, or add it to your previously created forms, they wouldn't all have the same field number so it may not work. This code will use the automatically generated unique invoice number and add the form name.
i.e. Form Name: "Yearly Subscription" Auto Invioce Number: "1234567890"
Info that Authorize.net receives: "1234567890-Yearly_Subscription"
I have found that instead of adding custom functions to your theme file, it is better to build a custom plugin and add them there instead. This way if your theme updates, you won't lose your functions. The code to create your plugin, along with the functions for your Authorize.net code is included below. Save this file as My_Custom_Functions_Plugin.php and upload it to your web host in the "wp-content/plugins/" folder and then activate it. Next time you need to add any customized functions, just add them at the end of this file.
<?php
/*
Plugin Name: My_Custom_Functions_Plugin
Plugin URL: http://WEBSITE
Description: Custom Functions and Scripts for WEBSITE
Version: 1.0.0
Author: NAME
Author URI: http://WEBSITE
*/
// Functions for apending form name to authorize.net invoice
add_filter( 'gform_authorizenet_transaction_pre_capture', 'invoice_num', 10, 4 );
function invoice_num( $transaction, $form_data, $config, $form ) {
$transaction->invoice_num = uniqid() . '-' . rgar( $form_data, 'form_title' );
gf_authorizenet()->log_debug( 'gform_authorizenet_transaction_pre_capture: ' . print_r( $transaction, 1 ) );
return $transaction;}
// End of Authorize.net Function
// Add any additional Functions below this comment line to keep your themes functions.php file from getting overwritten on theme updates. Copy and paste this comment line before each function and give it a description to help keep you organized about what your function does
?>
Hope this helps!

WordPress: get all meta data when user registers

I have a user registration form in the front end (in the Users admin section as well) with three extra fields (apart from default ones): birthday, country, language. their values are stored in usermeta table.
I have this action hook to retireve all meta data for the registered user:
add_action('user_register', 'new_user_func');
// user registration callback function
function new_user_func($userID) {
$newUser = get_user_meta( $userID );
$userMeta = array();
foreach ($newUser as $key => $value) {
$userMeta[$key] = $value[0];
}
//do something with $userMeta...
}
var_dump($userMeta) after submit doesn't give me the extra fields value though.. only defaults (first name, last name etc)
Anyone know what might be the case?
Did you try getting the values with:
$meta = get_the_author_meta($meta_key, $user_id);
Perhaps the meta values you add yourself isn't supported by get_user_meta() .
If this don't work either, perhaps you need to look on how you went about creating the new meta fields. Theres a pretty decent tutorial on how to do it here:
http://justintadlock.com/archives/2009/09/10/adding-and-using-custom-user-profile-fields
Read de Codex entry for user_register action, it says:
Not all user metadata has been stored in the database when this action is triggered.

Resources