Send thank you email in wordpress after user is redirected from other website - wordpress

This is the problem I am trying to find a solution to: I manage a wordpress site that deals with donations. There are 5 options. Once the user clicks on one of them they are sent to a third party site to make a donation. After they make the donation they are redirected back to my site with a set of data (name, email etc.). What I need to do is get that data and send a thank you email to the user. Is there some wordpress plugin I can use to handle the incoming data and send the email? Or maybe use a plugin like Contact form 7 to do it? I am not really familliar with wordpress. Really basic knowledge

The easiest way to do this would be to create a custom page template with logic to capture the data sent after donating in it and apply the template to a page.
E.g.
wp-content/themes/your-theme/ipn.php
<?php
/**
* Template Name: IPN
*/
// Grab the data that's returned, however it's returned.
$data = $_GET['data'];
// Use WordPress mail function to send your email
wp_mail( $to, $subject, $message, $headers, $attachments );
// Either redirect to another page or display a thank you message.
Then go into your admin, create a new page called IPN, select your page template from the drop down and publish. You can use the URL to this page to pass data back to it from the 3rd party site after payment.

Related

Redirect "dumb" URL to Author's custom post

I have created a website whereby users register and create their own templated profile pages. The profile pages are automatically created as Custom Posts upon registration, with the user being set as the Author of their specific post (profile).
(Users can only ever have one Custom Post)
I want to redirect a "dumb" URL like www.website.com/my-profile to a user's custom post when they are logged in.
For example, when John Smith visits www.website.com/my-profile he is directed to his profile page: www.website.com/users/john.smith
I have found many PHP solutions going the other way, but I can't seem to find a solution that does what I need. Any help would be greatly appreciated. Thanks!
This may not be the correct answer to the original query, but proved to be a solid workaround:
Instead of redirecting www.website.com/my-profile to www.website.com/users/john.smith every time it is entered in the URL bar, I created a shortcode that could be used when needed throughout the site.
add_shortcode('bt_redirect_user_link', 'bt_redirect_user_link');
function bt_redirect_user_link ($atts) {
// check if user is logged in
if (is_user_logged_in()) {
// get current user object
$current_user = wp_get_current_user();
// get user nickname
$user_nickname = $current_user->data->user_nicename;
// set the link href
$link_href = '/users/' . $user_nickname;
// output the link html
return $link_href;
}
}
Fortunately for me, the www.website.com/my-profile link (which needs to be redirected) is only available on buttons/icons visible to logged in users. This may not be a fully workable solution for websites that need to display the link to logged out users, and I assume IF/ELSE statements would needed to be added in those cases.

How to programmatically change the default messages in Contact Form 7?

I am trying to edit the error message for spam in the contact-form-7 plugin in WordPress. As of now it only shows a simple message with 'there was an error trying to send your message', I would like to change this. But I can not figure out where to find the place in the code where this message is sent from. I have found the default message, but once this is changed, this does not do anything.
Where can I find this?
There are 2 ways to change the default messages in CF7, one is using the admin cf7 form editor which has a tab 'Messages', while the 2nd way is to hook the 'wpcf7_messages' filter fired by the plugin once all the messages have been set,
//give a prioity >10 to ensure you filter hooks after those of the plugin.
add_filter('wpcf7_messages', 'change_spam_filter', 20,1);
function change_spam_filter($msgs){
$msgs['spam']['default'] = "this is a custom spam message";
return $msgs;
}
this filter only fires on the admin back-end and not on the front-end. If you need to filter the message when the form is submitted you can hook,
add_filter('wpcf7_display_message','',10,2);
function filter_spam_msg($message, $status){
if('spam' != $status) return $message;
$message = "this is a custom spam message";
return $message;
}
EDIT: note that as of v5.5 of the CF7 plugin, HTML formatted responses can longer be diplayed on form submission. To do this you will need to install an extension. See this answer.

Wordpress Contact form 7: can I send 3 different emails?

I have a contact form where people register his friend. The form sends the information to me and thank you email to user which register his friend , but I need send one more email to his friend with a different text . Is that possible with contact form 7 ?
Contact Form 7 has a wpcf7_mail_sent hook for this.
// ...in functions.php
add_action('wpcf7_mail_sent', function ($cf7) {
// Run code after the email has been sent
});
Since CF7 still doesn't do this itself, I wrote a basic plugin for it (More Mails for CF7). The crux of it is using CF7's hooks and functions to do most of the work for you:
Add another mail property (if it doesn't exist) with the filter hook wpcf7_contact_form_properties
Add another mail form section with the wpcf7_editor_panels filter hook.
Sanitise the incoming mail form data and assign it as a property of the form object in the wpcf7_save_contact_form action hook.
Allow it to be sent with the wpcf7_additional_mail filter hook.
It's not hard, each step is quite small. The relevant code is here, but you don't have to use any of the parts that create a settings page if you're happy setting a static number of extra mail messages in your code.

Notify email when someone's posted a review in WooCommerce

I noticed that Woocommerce's reviews are managed through Wordpress Comments. But why is it that Wordpress isn't notifying my email when someone posted a review to a product. I have set the "Email me whenever anyone posted a comment".
Is this function available in Woocommerce or i'm missing something?
Please advise, thanks everyone!
Regards, Ven
By default Wordpress sends a notification to the author of the product/post (the person who created the product in your instance). The suggested site owner (settings > general) is not the recipient of these notifications. This is where the trouble might start. This author information is in Woocommerce hidden and is hard to figure out who that is in your user database. It might be that the original author of the product doesn't exist anymore, and especially if the original author has been deleted from the database and you didn't move the contents of that user to a new user.
The default comment notifications are produced in this Wordpress file: wp-includes/pluggable.php
Below is a trick to override the recipient for the comment/review notification, put this code in your child-theme's functions.php and change the part example#example.com to your desired email recipient and you will receive a notification every time someone adds a comment/review to your site.
function new_comment_moderation_recipients( $emails, $comment_id ) {
return array( 'example#example.com' );
}
add_filter( 'comment_moderation_recipients', 'new_comment_moderation_recipients', 24, 2 );
add_filter( 'comment_notification_recipients', 'new_comment_moderation_recipients', 24, 2 );
I tested it and it works.
On the Wordpress Dashboard navigate to Settings > General and the Email address listed here is where you will get notifications.

Wordpress Form Submit button GETS (or POSTS) form data to external page

We have a wordpress website that does marketing display, but now we want to allow a customer to submit an email and selection to a separate website with a landing page that will handle the backend DB work and finish them in the other website.
Something like,
www.ourmarket.com/getdata (on Submit button click GETS to...)
www.ouradminsite/landingpage.aspx (which processes the data that the use will not see then...)
www.ouradminsite/login.aspx (where the user can now login)
I am not familiar with WP at all, but I was able to create a page with a form that has the textbox/combobox I need.
I thought it would be something simple, but somehow it seems not. I read about AJAX and doing something in functions.php and creating a custom .js file, but when working on the marketing site I find no way to add this type of function in.
My fall back is to have the WP page just have a link to a generic landing page where they enter data, but it would be visually jarring to the customer unless I duplicate the WP site for one page.
Is there an easy way to just tell WP to redirect to an external page with a GET?
UPDATE--------------
I like to think I'm making progress. I found a link that may have given me a good start. I added a function to the functions.php file located in my WP theme. It starts like this:
add_action("gform_post_submission_4", "set_post_content", 10, 2);
function set_post_content($entry, $form){
//Gravity Forms has validated the data
//Our Custom Form Submitted via PHP will go here
// Lets get the IDs of the relevant fields and prepare an email message
$message = print_r($entry, true);
// In case any of our lines are larger than 70 characters, we should use wordwrap()
$message = wordwrap($message, 70);
// Send
mail('myuser#mycompany.com', 'Getting the Gravity Form Field IDs', $message);
**wp_redirect("http://my.hearbuilder.com/hellomoto.aspx",301);**
}
From there I tried to edit the function to do that wp_redirect, just a simple one to start. This is added under the mail statement:
wp_redirect("http://my.hearbuilder.com/hellomoto.aspx",301);
From this link, when I fill out the form I can get the email, but the new page did not display. I added the exit; line and still got the same result, the page seems like it hangs.
The end result is that I need to have the new website landing page display (after it processes the data from the Wordpress form.
What am I still missing?
yes use wp_redirect()
if($_POST):
$textbox=$_POST['textboxname'];
$url= 'url'.'?custom=hello&textbox='.$textbox.'&anothervalue='.$anothervalue;
wp_redirect($url);
exit;
endif;
you can easily add the variables to the string as needed. The easiest way to control the url properly is to post the information to the same page , catch the post and redirect (place before get_header call or any output has started)
The other way is php Curl which is more difficult esp when dealing with .asp pages, but if you have access to the other server it makes figuring it out easier!

Resources