Created
August 24, 2017 06:50
-
-
Save joshuaiz/b1e8bf74a84b55622a1dbd1dfe8ea5cf to your computer and use it in GitHub Desktop.
Attempt to update GF Limit Choices value when user profile is updated (not working)
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
<?php | |
// just a sample function to see what's going on | |
// not tied to a particular action yet | |
// we are on a user profile edit screen | |
add_action( 'wp', function() { | |
$form_id = 4; // GF user registration form | |
$choice_field_id = 13; // ACF 'time_slots' field | |
$choice_value = ''; // initializing the variable (otherwise PHP 7 freaks out) | |
$field_key = "field_5996299aee5a9"; // ACF 'time_slots' field | |
$slots = get_field_object($field_key); | |
global $user_id; | |
echo $user_id; // returns nothing | |
$timeslots = get_field('time_slots'); | |
echo $timeslots; // returns nothing; why? | |
// without this how can I see which option is currently checked on the current user profile screen? | |
// need that for a conditional to update the GF Limit Choices $remaining_inventory value | |
if( $slots ) { | |
foreach( $slots['choices'] as $k => $v ) { | |
$choice_value = $v; | |
$remaining_inventory = GP_Limit_Choices::get_entries_left( $form_id, $choice_field_id, $choice_value ); | |
if ( $remaining_inventory == 0 ) { | |
echo '<li>Reserved: ' . $choice_value . '</li>'; // works | |
} else { | |
echo '<li>Available: ' . $choice_value . '</li>'; // works | |
} | |
} | |
} | |
wp(); // calling the function | |
?> |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment