Dennis Dallau
Forum Replies Created
-
UPDATE:
The below code does exactly what I want… Meaning: When 23/06/2020 SESSION 1 should be disabled, the time field automatically dessapears when both values match.
Now the only struggle (and I guess it has to do with a FOREACH missing) is that only the last entry of the REPEATER FIELD (with disabled date and session) works. The once before are being ignored.
// Apply conditions to fields add_filter('acf/prepare_field/name=bookings_field_time_session_1', 'yl_check_booking_exeptions_session_1'); function yl_check_booking_exeptions_session_1( $field ) { // Retrieve option values. Date value should be like: 20200611 (unformatted) if( have_rows('bookings_settings_disabled_exceptions', 'bookings') ) { while ( have_rows('bookings_settings_disabled_exceptions', 'bookings') ) { the_row(); if ( get_sub_field('bookings_settings_disabled_session', 'bookings') == '1' ) { $option_date = get_sub_field('bookings_settings_disabled_date', 'bookings', false); $date = date_i18n('Ymd', strtotime($option_date)); $session = get_sub_field('bookings_settings_disabled_session', 'bookings', false); // Add the condition to the field $field['conditional_logic'] = array( array( 'field' => 'field_5ed4181bd63dc', // Time field session 1 in the form 'operator' => '==', // If Value is different, then show the field 'value' => $session, // Compare against option page value ), array( 'field' => 'field_5ed4178dd63d7', // Datepicker fiels in the form 'operator' => '!=', // If Value is different, then show the field 'value' => $date, // Compare against option page value ) ); } // Return return $field; } } }
- This reply was modified 4 years, 9 months ago by Dennis Dallau.
- This reply was modified 4 years, 9 months ago by Dennis Dallau.
- This reply was modified 4 years, 9 months ago by Dennis Dallau.
First of all let me say: “Thank you for helping me… really.”
Although I know I’m soooo close (because I see changes in showing fields when I select values) but I’m not there yet because it does not do it right.
Maybe it helps letting you exactly know what I’m trying to accomplish:
I have an option (repeater field) with date and session to disable bookings.
F.i.
15/06/2020 NO BOOKINGS the WHOLE day
18/06/2020 NO BOOKINGS session 1 (so session 2 is available)I check these DATE and SESSION values with 2 fields in my form:
OPTION DATE >> Checks the value in the DATEPICKER
OPTION SESSION >> Checks the value in SELECT SESSION FIELD (Session 1 for lunch or Session 2 for dinner)So If OPTION DATE != DATEPICKER VALUE && OPTION SESSION != SELECT SESSION FIELD show FIELD X (in my case the time field but can be anything)
Here’s what I have so far:
// Apply conditions to fields add_filter('acf/prepare_field/name=bookings_field_time_session_1', 'yl_check_booking_exeptions_session_1'); add_filter('acf/prepare_field/name=bookings_field_time_session_2', 'yl_check_booking_exeptions_session_1'); function yl_check_booking_exeptions_session_1($field){ // Retrieve option values. Date value should be like: 20200611 (unformatted) if( have_rows('bookings_settings_disabled_exceptions', 'bookings') ) { while ( have_rows('bookings_settings_disabled_exceptions', 'bookings') ) { the_row(); $option_date = get_sub_field('bookings_settings_disabled_date', 'bookings', false); $date = date_i18n('Ymd', strtotime($option_date)); $session = get_sub_field('bookings_settings_disabled_session', 'bookings', false); } } // Add the condition to the field $field['conditional_logic'] = array( array( 'field' => 'field_5ed4181bd63dc', // SELECT SESSION FIELD 'operator' => '!=', // If Value is different, then show the field 'value' => $session, // Compare against option page value ), array( 'field' => 'field_5ed4178dd63d7', // DATEPICKER FIELD 'operator' => '!=', // If Value is different, then show the field 'value' => $date, // Compare against option page value ) ); // Return return $field; }
- This reply was modified 4 years, 9 months ago by Dennis Dallau.
I understand you completely but I’m not sure how to add a second (OR) array.
This does not work:
// Apply conditions of my_field_1, my_field_2 & my_field_3 add_filter('acf/prepare_field/name=bookings_field_time_session_1', 'yl_check_if_date_is_an_exeption'); add_filter('acf/prepare_field/name=bookings_field_time_session_2', 'yl_check_if_date_is_an_exeption'); function yl_check_if_date_is_an_exeption($field){ // Retrieve option value. Value should be like: 20200611 (unformatted) if( have_rows('bookings_settings_disabled_exceptions', 'bookings') ) { while ( have_rows('bookings_settings_disabled_exceptions', 'bookings') ) { the_row(); $date = get_sub_field('bookings_settings_disabled_date', 'bookings', false); $option_date = date_i18n('Ymd', strtotime($date)); } } // Bail early if no option date found if (empty($option_date)) return $field; // Add the condition to the field $field['conditional_logic'] = array( array( 'field' => 'field_5ed4178dd63d7', // >>>>>>>>>> Field key of the FIRST field of the form 'operator' => '!=', // If Value is different, then show the field 'value' => $option_date, // Compare against option page value array( 'field' => 'field_5ed4178dd63d7', // >>>>>>>>>> Field key of the OR field of the form 'operator' => '!=', // If Value is different, then show the field 'value' => $option_date, // Compare against option page value ) ) ); // Return return $field; }
I got it to work with the following code:
// Apply conditions of my_field_1, my_field_2 & my_field_3 add_filter('acf/prepare_field/name=bookings_field_time_session_1', 'yl_check_if_date_is_an_exeption'); add_filter('acf/prepare_field/name=bookings_field_time_session_2', 'yl_check_if_date_is_an_exeption'); function yl_check_if_date_is_an_exeption($field){ // Retrieve option value. Value should be like: 20200611 (unformatted) if( have_rows('bookings_settings_disabled_exceptions', 'bookings') ) { while ( have_rows('bookings_settings_disabled_exceptions', 'bookings') ) { the_row(); $date = get_sub_field('bookings_settings_disabled_date', 'bookings', false); $option_date = date_i18n('Ymd', strtotime($date)); } } // Bail early if no option date found if(empty($option_date)) return $field; // Add the condition to the field $field['conditional_logic'] = array( array( array( 'field' => 'field_5ed4178dd63d7', // Field key of the date field of the form 'operator' => '!=', // If Value is different, then show the field 'value' => $option_date, // Compare against option page value ) ) ); // Return return $field; }
The only problem (so to speak) is that this function overwrites the CONDITIONAL LOGIC set in ACF itself.
I guess there isn’t a way to ADD this to the logics rather than completely REPLACE it?
Forum: Plugins
In reply to: [Advanced Custom Fields: Extended] Output array of option fieldtnx. solved
I got out working.
Forum: Plugins
In reply to: [Advanced Custom Fields: Extended] Post ID in email action?Works like a charme. Solved!!
Many tnx m8. Day by day I’m setting new boundaries with your oh so great plugin.
Ok thanks I will get into all of that.
I so love your plugin and I would like to keep all ’email contents’ together, so…
With my own code (saved in Code Snippets) is it possible to still activate email actions saved in your plugin?
In example:
I have created my own working code to activate your plugins email actions so I can edit the emails subject, content, and so on easily within the booking-form email action to keep all, together and clean.Your plugin is based on frontend but with custom code email actions can be triggered in backend?
I understand I can send emails with post status change programmatically but I would like to have just 1 backend item to edit the emails subject, content, and so on. Your UI it just to good to ignore…. get my drift?
Forum: Plugins
In reply to: [Advanced Custom Fields: Extended] Condition for sending out an email actionThis is offtopic so I will post a new and clear question.
Forum: Plugins
In reply to: [Advanced Custom Fields: Extended] Condition for sending out an email actionThe logic is here right? But it just doesn’t send out an email:
add_action('acf/save_post', 'my_acf_save_post'); function my_acf_save_post($post_id) { // Get newly saved values. $values = get_fields($post_id); // Retrieve user input $status = get_field('bookings_field_status', $post_id); if ($status === 'confirmed') { function yl_send_customer_email_status_confirmed($args, $form, $action) { return $args; } } } add_filter('acfe/form/submit/email_args/action=bookings-email-customer-confirmed', 'yl_send_customer_email_status_confirmed', 10, 4);
Forum: Plugins
In reply to: [Advanced Custom Fields: Extended] Condition for sending out an email actionDon’t know what I was thinking with the code above… I guess I was asleep. Here’s the correct code I have so far:
function yl_send_admin_email_new_booking($args, $form, $action) { // Retrieve user input $status = get_field('bookings_field_status'); if ($status === 'pending') { return $args; } } add_filter('acfe/form/submit/email_args/action=bookings-email-admin-new-booking', 'yl_send_admin_email_new_booking', 10, 4); function yl_send_customer_email_status_pending($args, $form, $action) { // Retrieve user input $status = get_field('bookings_field_status'); if ($status === 'pending') { return $args; } } add_filter('acfe/form/submit/email_args/action=bookings-email-customer-pending', 'yl_send_customer_email_status_pending', 10, 4); function yl_send_customer_email_status_confirmed($args, $form, $action) { // Retrieve user input $status = get_field('bookings_field_status'); if ($status === 'confirmed') { return $args; } } add_filter('acfe/form/submit/email_args/action=bookings-email-customer-confirmed', 'yl_send_customer_email_status_confirmed', 10, 4); function yl_send_customer_email_status_changed($args, $form, $action) { // Retrieve user input $status = get_field('bookings_field_status'); if ($status === 'changed') { return $args; } } add_filter('acfe/form/submit/email_args/action=bookings-email-customer-changed', 'yl_send_customer_email_status_changed', 10, 4); function yl_send_customer_email_status_canceled_by_guest($args, $form, $action) { // Retrieve user input $status = get_field('bookings_field_status'); if ($status === 'canceled by guest') { return $args; } } add_filter('acfe/form/submit/email_args/action=bookings-email-customer-canceled-by-guest', 'yl_send_customer_email_status_canceled_by_guest', 10, 4); function yl_send_customer_email_status_canceled_by_us($args, $form, $action) { // Retrieve user input $status = get_field('bookings_field_status'); if ($status === 'canceled by us') { return $args; } } add_filter('acfe/form/submit/email_args/action=bookings-email-customer-canceled-by-us', 'yl_send_customer_email_status_canceled_by_us', 10, 4);
So the above code works like a charme when the form is filled in the first time. It does not work when you update the STATUS fields within a saved post…
Any ideas to achieve that?
- This reply was modified 4 years, 10 months ago by Dennis Dallau.
- This reply was modified 4 years, 10 months ago by Dennis Dallau.
Forum: Plugins
In reply to: [Advanced Custom Fields: Extended] Condition for sending out an email actionWorks fantastic and because of your goodwill, I will give mine by posting (almost the whole) code to create an interactive reservation system. At the bottom I have one question to finalize this.
function yl_send_admin_email_new_booking($args, $form, $action) { // Retrieve user input $status = get_field('bookings_field_status'); // If user input is Confirmed if ($status === 'In behandeling') { // Do not send the e-mail return false; } // Return normally for other case return $args; } add_filter('acfe/form/submit/email_args/action=bookings-email-admin-new-booking', 'yl_send_admin_email_new_booking', 10, 4); function yl_send_customer_email_status_pending($args, $form, $action) { // Retrieve user input $status = get_field('bookings_field_status'); // If user input is Confirmed if ($status === 'In behandeling') { // Do not send the e-mail return false; } // Return normally for other case return $args; } add_filter('acfe/form/submit/email_args/action=bookings-email-customer-pending', 'yl_send_customer_email_status_pending', 10, 4); function yl_send_customer_email_status_confirmed($args, $form, $action){ // Retrieve user input $status = get_field('bookings_field_status'); // If user input is NOT Confirmed if ($status !== 'Bevestigd') { // Do not send the e-mail return false; } // Return normally for other case return $args; } add_filter('acfe/form/submit/email_args/action=bookings-email-customer-confirmed', 'yl_send_customer_email_status_confirmed', 10, 4); function yl_send_customer_email_status_changed($args, $form, $action){ // Retrieve user input $status = get_field('bookings_field_status'); // If user input is NOT Confirmed if ($status !== 'Gewijzigd') { // Do not send the e-mail return false; } // Return normally for other case return $args; } add_filter('acfe/form/submit/email_args/action=bookings-email-customer-changed', 'yl_send_customer_email_status_changed', 10, 4); function yl_send_customer_email_status_canceled_by_guest($args, $form, $action){ // Retrieve user input $status = get_field('bookings_field_status'); // If user input is NOT Confirmed if ($status !== 'Geannuleerd door gast') { // Do not send the e-mail return false; } // Return normally for other case return $args; } add_filter('acfe/form/submit/email_args/action=bookings-email-customer-canceled-by-guest', 'yl_send_customer_email_status_canceled_by_guest', 10, 4); function yl_send_customer_email_status_canceled_by_us($args, $form, $action){ // Retrieve user input $status = get_field('bookings_field_status'); // If user input is NOT Confirmed if ($status !== 'Geannuleerd door ons') { // Do not send the e-mail return false; } // Return normally for other case return $args; } add_filter('acfe/form/submit/email_args/action=bookings-email-customer-canceled-by-us', 'yl_send_customer_email_status_canceled_by_us', 10, 4);
One question to complete this (I will post when 100% done for all):
The proces goes like this:
– Customer fills out form to make a booking
– Status is auto set to: In behandeling (pending)
– A post is created with all ACF fields included
– An NEW BOOKING email is send to admin
– An BOOKING RECEIVED email is send to customerBut…
I want to send out an other automated email when I change the saved STATUS to ‘confirmed’.
Explained: When I change the status from ‘pending’ to ‘confirmed’ in the newly created post no email is going out to the customer saying >> Conmfirmed
How do I let the email-action gets triggered when updating a (custom type) post with the changed STATUS field inside?
Forum: Plugins
In reply to: [Advanced Custom Fields: Extended] Condition for sending out an email actionAnybody?
Forum: Plugins
In reply to: [Advanced Custom Fields: Extended] Condition for sending out an email actionSo I’m looking for something like this:
add_action('acfe/form/submit/form=yl_contact_form', 'my_form_submit', 10, 2); function my_form_submit($form, $post_id){ /** * Get the form input value named 'my_field' * This is the value entered by the user during the form submission */ $my_field = get_field('status'); $my_field_unformatted = get_field('status', false, false); if($my_field === 'Confirmed'){ // Trigger email action yl-email-admin } /** * Get the field value 'my_field' from the post ID 145 */ $post_my_field = get_field('my_field', 145); $post_my_field_unformatted = get_field('my_field', 145, false); }
This would open up soooooo many new possibilities ??