ACF fields ,select where a email goes,apply conditional logic - wordpress

I have pages with ACF(advanced custom fields) setup with different fields.
I want to be able to access that data and apply a
conditional logic.
To apply the conditional logic there will be a contact form
where the public will fill in and dependant on what they choose
an email will be sent out to different recipients.
Fields are:
Destination: of which there are 5 to choose from
type of place: house, apartment ( drop down)
email address: "email"
Contact form will have
name:
Phone:
email address:
Destination: (acf) select which ones
type of place (acf) selct which ones
Date picker
how many people Adult Children
Accommodation package (select or both)
message
So from the 3 fields... destination, type of place and email
I want an email to go to the email recipients who meet the criteria selected
with all of the mentioned above data to be sent.
with a default email sent to the wp account.
What is the best way to tackle this?

You have here 2 solutions :
First one, the easiest, you create 5 contact form, and depending on the acf value, you print the corresponding contact form. This solution might not been really beautiful, but is working well.
Seconde solution, a little bit harder, would be to add an input hidden in your form. Set the recipient email into this input hidden. Then hook, in your function.php the wpcf7_before_send_mail() hook. During this hook, replace the recipient mail set in CF7 to the one set in input hidden.

Related

Creating WooCommerce placeholder for Emails sent

My client, a courier company, is using delivery software that is able to track with both WooCommerce order no. and ID, which means it requires both order no. and ID ("wc_order_abcdefg") to work, I believe this falls in the phpmyadmin database of post_password column.
Full tracking ID goes like: wc_order_abcdefg.66
So in the WooCommerce email settings, it only has {order_number}. How do I create one for {order_id}?
It looks like, your shipment tracking number is {order_key}.{order_number}.
Once you get hold of the order object, you can get its key simply with: $order->get_order_key().
{order_key} is not available as an email placeholder. So in order to include it in the email sent to the customer, you have different options depending on where you want it to be displayed. For example:
You could include the tracking number in the body of the email. In this case, you can override one of the WooCommerce email templates (e.g. email-order-details.php). See the WooCommerce docs for more info on how to override templates.
You could include the tracking number in the subject of the email. In this case, you can use the woocommerce_email_subject_customer_completed_order filter. E.g. (this snippet should be added to your functions.php):
add_filter( 'woocommerce_email_subject_customer_completed_order', 'add_tracking_number_to_email_subject', 1, 2 );
function add_tracking_number_to_email_subject( $subject, $order ) {
return sprintf( 'Thank you for your order! Your shipment tracking number is: %s.%s', $order->get_order_key(), $order->get_id() );
}

contact form 7 send mail according to user response

I have set up a Contact Form 7 on my website and It has a drop down so the user can select any option from the drop down . so my problem is this that when a user select from any of the 3 option , a mail has been sent to the user who has submitted a form but I want to sent the mail according to the desired option because I have three different mails for 3 different option
So there is only one option for mailto . Is there any hook to send the mail accoridng to user selection
I'm not 100% sure of what you want, but for what I understand you need to send the email to a different address according to the selected option in the dropdown, right?
The pipes feature allow that.
Your select tag would be something like that:
[select your-recipient "CEO|ceo#example.com"
"Sales|sales#example.com"
"Support|support#example.com"]
With that you'll have the following dropdown in your form:
But in the email the [your-recipient] tag will produce the value after the "|" character. So you can put this tag inside the Mail fields (in your case, it should be in the "To" field, because you want to send the email to that address).
So, if for example an user select "CEO" in the dropdown, the email will be sent to ceo#example.com. And if another user select "Sales", then it will go to sales#example.com.

Wordpress: Counter for page views to be inserted in a different page

I have been looking for a plugin in wordpress that allows me to insert a page view counter in a different page: I´ll explain;
In page A I have buttom with a contact form to vote a video (it is a video contest). This contact form sends the voter an email with a link to page B so that they can validate their email this way. Every visit to page B will be counted as a vote.
The thing is that I want to count the number times that page B is accessed to show it in page A (to show the number of votes next to the video).
It seems pretty straightforward but I can´t find an easy way to do this. Do you think you could help me?
Thanks!
Guzmán
If a very small number of people will access the page you can just store a value in WordPress and add to it each time. If you expect a lot of users on the page at once you may need a more complex method.
For a lightly trafficed page, with the risk that some visits might not be counted you could leverage the post meta and simply store a counter variable. If two people viewed the page at the same time they could get the same value for the counter variable and so they would not properly increment the variable.
You could add this to the template for the page in question:
$vcount = get_post_meta($post->ID, "view_counter");
add_post_meta($post->ID, "view_counter", $vcount+1, true);
So two people accessing the page would end up with equal $vcount variables. To display the count you'd just need the post id for the post you saved the meta to: print get_post_meta(<POSTIDHERE>, "view_counter", true);
If you need to have a more robust solution, you'd want to store a unique value for each visitor and then to report the total you would count the values and display it. So you could store the visitor's IP address as a multi-value meta:
add_post_meta($post->ID, "view_counter", $_SERVER['REMOTE_ADDR'], false);
Then to display the count you'd need to count the number of post meta values stored with the view_counter key:
$ips = get_post_meta(<POSTIDHERE>, "view_counter", false);
$views = count($ips);
print "Total views: $views";
This is just a sample solution, you should probably check to see if an IP already exists and consider throttling individual IPs. You could also risk filling your database if you have a small shared server unless you write some additional code to keep this from being abused since it adds data to your database on every page view. Finally this will not work correctly if you have any type of caching enabled.
Depending on the plugin that you are using for your contact form you may also be able to report the number of times that the contact form was submitted by querying the database directly.
For more information see the documentation for add_post_meta and get_post_meta
(disclaimer, code written from memory and documentation, not tested)

Logic in merge tags, Gravity Forms

I am creating a few Notifications in Gravity Forms and I would like to use some "if/else" logic based on field entries.
For example, I have a Buyer 1 Name field and a checkbox that asks "Would you like to add another buyer?" When they check it, a new Name field appears for Buyer 2. In my Notification I would like to say "The following buyer...." if only the first name is completed, and "The following buyers..." if the 2nd name is filled in. Basically make buyer plural. I could give about 10 more examples of needing logic INSIDE the merge tags, really surprised this isn't available. Thoughts?
You want to use a Gravity Forms conditional shortcode in your notification message. It looks like this:
[gravityforms action="conditional" merge_tag="{Field:1}" condition="is" value="desired value"]Show this content if the field is equal to the field value I specified earlier[/gravityforms]
You can also check out this full tutorial (images included).

How do I validate a nodereference field in a custom node form in Drupal 6?

I have an autocomplete nodereference field (field_hostnamelastref) in a custom pass-node-form.tpl.php. The field references four items (last name, first name, an id #, and status) generated from tokens in an autotitle from another content type.
When entering a last name in the nodereference field, if the corresponding status for that last name is "SUSPENDED", I would like to be able to validate that field with an error message and block form submission.
This is my first attempt at writing my own validation and am not having any luck. Have tried many different ways ereg, preg-match and strpos. Below is my latest attempt:
<?php
function pass_validate($form_id,$form_values) {
$status = 'SUSPENDED';
if (strpos ($form_values['hostnamelastref'], $status)) {
form_set_error('hostnamelastref', t('The account for this person has been suspended.', array('#type' => $type->name)));
}
}
?>
Not sure if I'm even in the ball park on this. Any help much appreciated!
If you can pass the SUSPENDED information somehow to views, then you can limit the nodes one chooses in the nodereference using a view. Then nodereference will take care for validation if the user entered a node not in the list.
But I am not sure I understood your question.

Resources