Gravity Forms - Compare value against another field - forms

Hoping someone can shed some light on this. I have a registration form setup in Gravity Forms for the registration of students. According to law a students guardian/parent needs to give consent for students under the age of 18. I have setup a conditional "Guardian/Parent" email field that only shows if the student is under the age of 18.
So X2 email fields are present in the form, one for the student and one for the guardian/parent. Once the forms is submitted, the activation mail is sent only to the guardian email address.
My problem is that at the moment the same email address can be pout in both the guardian/parent and student email. I would like to validate the 2 email fields and ensure that they are not the same.
I tried the following, but it has no effect at all.
add_filter( 'gform_field_validation_12_3', function ( $result, $value, $form, $field ) {
$master = rgpost( 'input_11' );
if ( $result['is_valid'] && $value == $master ) {
$result['is_valid'] = false;
$result['message'] = 'Please enter a different email.';
}
return $result;
}, 10, 4 );
The "12" in "gform_field_validation_12_3" represent my form_id and the "3" represents the guardian/parent field_id
The "11" in "$master = rgpost( 'input_11' );" represents my student email field_id
It simple does not validate the fields and submits the form even though I have the same email in both fields....

If email confirmation is enabled, you'll want to change this line:
if ( $result['is_valid'] && $value == $master ) {
to this:
if ( $result['is_valid'] && $value[0] == $master ) {
The issue is that when email confirmation is enabled, the $value is an array not a string. You can just get the first value from the array and it should work as expected.
If you don't want to fuss with having to know all of this, feel free to use this snippet I just wrote. It will also handle multiple fields and multiple groups of "unique" fields.
http://gravitywiz.com/gravity-forms-require-unique-values-for-different-fields/

Related

WooCommerce pdf attachment to custom email is not working

I am using WooCommerce order status manager plugin for custom order statuses and emails notifications. I have created custom status for paid orders via card pay - card-on-hold.
I have also created custom email which will be triggered when statuses will change from receivet to card-on-hold.
my code is:
add_filter( 'woocommerce_email_attachments', 'attach_manual_pdf_to_email', 10, 3);
function attach_manual_pdf_to_email ( $attachments, $status , $order ) {
$allowed_statuses = array( 'customer_processing_order', 'customer_on_hold_order', 'customer_order_status_email' );
if( isset( $status ) && in_array ( $status, $allowed_statuses ) ) {
$dokument = get_template_directory() . '/woocommerce/emails/attach.pdf';
$attachments = $dokument;
}
return $attachments;
}
Email Ids customer_processing_order and customer_on_hold_order works like a charm.
But customer_order_status_email which is php template for order status manager is not working. It is located in betheme/woocommerce/emails/customer-order-status-email.php and I did also try to move it to same locations where other templates are but that did not help.
Any idea how to make this working please?
okay i did find a solution:
i did use echo '<pre>'; print_r($email->id); echo '</pre>' in template of an email which printed me an email ID. i used this id in my allowed statuses and it is working now.

Is there a filter or hook t change the WC_Tax::get_rate_label( $key ) in woocommerce?

I am trying to change the Tax label on the cart, checkout order-review and email.
I have tried to create a function with 'woocommerce_get_order_item_totals' and also with 'woocommerce_get_formatted_order_total' No luck. It either remove all or adds a new line but changing the $tax_totals[ $code ]->label
I have a checkbox which gives customers to possibility to apply Tax-exempt for the order. This is all working very good.
If selected it will set TAX Amount to 0.00 but the label keeps on VAT or TAX or BTW (Dutch label)
I added zero-rates in the backend,
Phrase matches used to identify VAT (VAT, V.A.T, IVA, I.V.A., Value Added Tax, TVA, T.V.A., BTW, B.T.W., Tax Exempt, vrijgesteld van BTW)
I added zero-rate by country code
GB Tax Exempt (0%)
NL vrijgesteld van BTW (0%)
And still it shows on the cart, checkout, order-review and email as VAT or(BTW) whatever the country is.
This is what I want to change
I have been looking already for days to find a working solution with no luck.
But I found a solution just now, not sure if it is a hack or good coding but it works for me.
I have this code inside my function.
add_action( woocommerce_checkout_update_order_review','taxexempt_checkout_based_on_checkbox');
function taxexempt_checkout_based_on_checkbox( $post_data) {
global $woocommerce;
$woocommerce->customer->set_is_vat_exempt( false );
parse_str($post_data);
if ( $billing_taxexempt === '1' && $billing_confirmed === '1' &&
!empty($billing_signature) && ! empty($billing_declaration)){
$woocommerce->customer->set_is_vat_exempt( true );
}
}
This will apply the tax-exempt to the order.
I added a filter to this just below ....set_is_vat_exempt( true )..
add_filter( 'woocommerce_countries_tax_or_vat', function () { return __( 'Tax Exempt', 'woocommerce' ); });
And I added a function I found //Change "Billing Details" text to "Shipping Details" on Woocommerce checkout page
I changed it a little bit but it works for me.
function wc_change_field_strings( $translated_text, $text, $domain ) {
$language = get_locale();
$domain = 'woocommerce';
if($language == 'en_GB' ){
switch ( $translated_text ) {
case 'Tax Exempt' :
$translated_text = __( 'Tax Exempt', $domain );
break;
}
return $translated_text;
}
if($language == 'nl_NL' ){
switch ( $translated_text ) {
case 'Tax Exempt' :
$translated_text = __( 'vrijgesteld van BTW', $domain);
break;
}
return $translated_text;
}
}
add_filter( 'gettext', 'wc_change_field_strings', 20, 3 );
Have to add the default case, will do later but it works for, this solution.
Maybe it will work for somebody else or if you have a better solution, let me know.
And the result looks like this.

Gravity Forms Multi Page Losing POST value

I have a complex Gravity Form built, it has 10 pages. I am using fields to build a "string" that I then match to a CPT name to get meta data from to display a selection, based on user choices in the form.
One field I have is not holding its value in POST. I can see it when I select the value on the page, then when I click to next page the value is still there. However, after two pages the value ( and field ) disappear from POST.
This is the function I have put together that builds my product string.
add_filter( 'gform_pre_render_12', 'display_choice_result' );
function display_choice_result( $form ) {
$current_page = GFFormDisplay::get_current_page( $form['id'] );
$html_content = "";
$prod_string = "";
if ( $current_page >= 10 ) {
foreach ( $form['fields'] as &$field ) {
// Check for a class of "product-builder-item" on the field
// I use this as another way to denote what fields to add to string
if ( strpos( $field->cssClass, 'product-builder-item' ) === false ) {
continue;
}
//gather form data to save into html field (Field ID 14 on Form ID 12)
//exclude page break and any hidden fields
if ( $field->id != 14 && $field->type != 'page' ) {
$is_hidden = RGFormsModel::is_field_hidden( $form, $field, array() );
$populated = rgpost( 'input_' . $field->id );
// Make sure the field we are getting the value from is not hidden and has a value
if ( !$is_hidden && $populated !='' ) {
$html_content .= '<li>' . $field->label . ': ' . rgpost( 'input_' . $field->id ) . '</li>';
$prod_string .= rgpost( 'input_' . $field->id );
}
}
}
// Do a bunch of stuff here with the $prod_string variable
// ...
// ...
// ...
}
return $form;
}
Screenshots showing the POST disappearing..The POST field in question is input_22 with a value of 18000
This is one page after I choose from the field
This is two pages after,
Anyone run into this before or have any idea why it would be disappearing?
Thank you.
I was having the same exact issue as you described. I realized that a jQuery function was interfering with Gravity Form process. The jQuery function was set to change a zip code field from type text to tel so the number pad would open up on mobile devices. This is what was causing my issue.

Woocommerce - Change order received text after redirecting from PayPal with IPN

I like to change the thank you page text in case the customer already paid via paypal.
Redirecting via PayPal works fine. Order status is "processing", ok.
But how can I change the thank you text on the redirecting page (https://www.example.com/checkout/order-received/)
I tried the following, with no success:
function my_update_order_status() {
$order = new WC_Order($order_id);
if ($order_status == 'processing')
echo 'NEW MESSAGE';
else
echo 'NOT PAID TEXT';
}
add_filter('woocommerce_thankyou_order_received_text', 'my_update_order_status', 10, 2);
There is an explanation on how to change the thank you page here:
https://wordpress.org/support/topic/how-to-edit-the-thank-youorder-received-page
If you don't wish to do any template modifying then you can include the order received function to adjust it. For example:
function isa_order_received_text( $text, $order ) {
$new = $text . ' All received and an email is on its way to you!.';
return $new;
}
add_filter('woocommerce_thankyou_order_received_text', 'isa_order_received_text', 10, 2 );
The above with add text to the current text output.

Virtuemart / User Fields

I have added a field in 'Manage User Fields' & when an email is sent to the administrator notifying them of the new user registration, I want to include this new field.
I have written some code to get this new field from #__vm_user_info in /administrator/components/com_virtuemart/classes/ps_shopper.php, in the _sendMail function, as well as added the variable to $message2.
ASEND_MSG has been modified to accept the parameter, but the field is not included in the email to the admin when a user is created. When I go look in the table, the data is there. So to trouble shoot, I hard coded a user name in the select statement, added another user & the correct value was sent for the hard coded user, not the one just added. I am now thinking that it is a commit issue with MySQL, so I put a sleep(4) in the code before I attempt to get the value...no luck.
Can anyone shine some light on this for me??
LarryR....
administrator/components/com_virtuemart/classses/ps_shopper.php
Need to add with the following code in function add() before "return true" line :
/**************************** ***********************/
$pwd = $_POST['password'];
$db = JFactory::getDBO();
$query = "SELECT id, name, email, username"
. "\n FROM #__users"
. "\n ORDER by id DESC LIMIT 1"
;
$db->setQuery( $query );
$rows = $db->loadObjectList();
$namee = $rows[0]->name;
$emaill = $rows[0]->email;
$usern = $rows[0]->username;
$pwd;
$lid = $rows[0]->id;
$dbv = new ps_DB;
echo $query = "SELECT *"
. "\n FROM #__{vm}_user_info"
. "\n WHERE user_id=$lid"
;
$dbv->setQuery( $query );
$fid = $db->loadObjectList();
$field = $fid[0]->extra_field_1;
$user = clone(JFactory::getUser());
$usersConfig = &JComponentHelper::getParams( 'com_users' );
if ($usersConfig->get('allowUserRegistration') == '0') {
JError::raiseError( 403, JText::_( 'Access Forbidden' ));
return false;
}
// If user activation is turned on, we need to set the activation information
$useractivation = $usersConfig->get( 'useractivation' );
if ($useractivation == '1')
{
jimport('joomla.user.helper');
$user->set('activation', md5( JUserHelper::genRandomPassword()) );
$user->set('block', '1');
}
$component = 'com_user';
$activation_link = $mosConfig_live_site."/index.php?option=$component&task=activate&activation=".$user->get('activation');
$this->_sendMail( $namee , $emaill, $usern, $pwd, $activation_link);
/************************************************** Spinz ********************************************/
Note : Here we created the mail function for username and password to users mail.
administrator/components/com_virtuemart/classses/ps_shopper.php
Need to comment the line in function register_save() before "return true" line:
// Send the registration email
//$this->_sendMail( $name, $email, $username, $password, $activation_link );
Note: Here the mail function generated we need to comment that mail functions and create another mail function in add() function of ps_shopper.php in first point.
administrator/components/com_virtuemart/classses/ps_shopper.php
Need to get the extra added field (extra_field_1) in jos_vm_user_info table in the function _sendmail() with following code and that field sent through the mail to user.
/****************************************************************/
$db = JFactory::getDBO();
$query = "SELECT id, name, email, username"
. "\n FROM #__users"
. "\n ORDER by id DESC LIMIT 1"
;
$db->setQuery( $query );
$rows = $db->loadObjectList();
$lid = $rows[0]->id;
$dbv = new ps_DB;
$query = "SELECT *"
. "\n FROM #__{vm}_user_info"
. "\n WHERE user_id=$lid"
;
$dbv->setQuery( $query );
$fid = $db->loadObjectList();
$field = $fid[0]->extra_field_1;
$subject = sprintf ($VM_LANG->_('SEND_SUB',false), $name, $mosConfig_sitename);
$subject = vmHtmlEntityDecode($subject, ENT_QUOTES);
if ($mosConfig_useractivation=="1"){
$message = sprintf ($VM_LANG->_('USEND_MSG_ACTIVATE',false), $name, $mosConfig_sitename, $activation_link, $mosConfig_live_site, $username, $pwd, $field );
} else {
$message = sprintf ($VM_LANG->_('PHPSHOP_USER_SEND_REGISTRATION_DETAILS',false), $name, $mosConfig_sitename, $mosConfig_live_site, $username, $pwd, $field);
}
/*************************************/
Note :
Initialize the variable "$field" get the extra added field value using query. Then that the extra field value is assigned by message section of the mail.(initialize variable $field having the a value added extra fields in virtuemart).
administrator/components/com_virtuemart/languages/common/english
replace the messages for the following code:
'USEND_MSG_ACTIVATE' => 'Hello %s,
Thank you for registering at %s. Your account is created and must be activated before you can use it.
To activate the account click on the following link or copy-paste it in your browser:
%s
After activation you may login to %s using the following username and password:
Username - %s
Password - %s
Degree - %s'
2.'PHPSHOP_USER_SEND_REGISTRATION_DETAILS' => 'Hello %s,
Thank you for registering at %s. Your customer account has been created.
You may login to %s using the following username and password:
Username - %s
Password - %s
Degree - %s
'
Note:
The extra added values assigned by the string %s in language file.
The message having the string values of extra added field value in virtuemart.
The degree shows the added extra field