How to set option values dynamically,
and how to set a default selected option value too.
Create this directory and file:
/wp-content/mu-plugins/s2-hacks.php
- Code: Select all
- <?php
 /*
 Setting options dynamically for Custom Registration Fields.
 */
 add_action ("ws_plugin__s2member_before_custom_field_gen", "my_dynamic_field_options");
 function my_dynamic_field_options ($vars = array ())
 {
 $_field = &$vars["__refs"]["_field"]; /* By "reference". */
 /* See: http://www.php.net/manual/en/language.references.spot.php. */
 /**/
 if ($_field["id"] === "country_code")
 {
 $_field["options"] = "US|United States|default" . "\n";
 $_field["options"] .= "CA|Canada" . "\n";
 $_field["options"] .= "VI|Virgin Islands (U.S.)";
 }
 }
 /*
 Setting a default value for Custom Registration Fields.
 */
 add_action ("ws_plugin__s2member_before_custom_field_gen", "my_dynamic_field_values");
 function my_dynamic_field_values ($vars = array ())
 {
 $references = &$vars["__refs"]; /* Array of variable "references". */
 $_field = &$vars["__refs"]["_field"]; /* By "reference". */
 /* See: http://www.php.net/manual/en/language.references.spot.php. */
 /**/
 if ($_field["id"] === "country_code")
 {
 if (empty ($references["_submission"]) && empty ($references["_value"]))
 /* If a form was not just submitted. And, there is no default value. */
 
 $references["_value"] = "CA"; /* Set the default value. */
 }
 }
 ?>

I'm also attaching a video tutorial on this topic,
where I explain how this code works in great detail.
MP4 Video file: http://www.s2member.com/wp-content/uplo ... ically.mp4

 
 




 
 




