LLMS_Form_Handler::maybe_modify_required_address_fields( array $posted_data, string $location, array[] $fields )
Modify LifterLMS Fields to allow some address fields to be conditionally required.
Description Description
Uses available country locale information to remove the "required" attribute for state and zip code fields when a user has chosen a country that doesn’t use states and/or zip codes.
Parameters Parameters
- $posted_data
-
(array) (Required) User submitted form data (passed by reference).
- $location
-
(string) (Required) Form location ID.
- $fields
-
(array[]) (Required) Array of LifterLMS Form Fields (passed by reference).
Return Return
(void)
Source Source
File: includes/forms/class-llms-form-handler.php
public function maybe_modify_required_address_fields( &$posted_data, $location, &$fields ) { // Only proceed if we have a country to review. if ( empty( $posted_data['llms_billing_country'] ) ) { return; } $country = $posted_data['llms_billing_country']; $info = llms_get_country_address_info( $country ); // Fields to chek. $check = array( 'llms_billing_city' => 'city', 'llms_billing_state' => 'state', 'llms_billing_zip' => 'postcode', ); foreach ( $check as $post_key => $info_key ) { $index = LLMS_Forms::instance()->get_field_by( $fields, 'name', $post_key, 'index' ); // Field exists, no data was posted, and the field is disabled (is `false`) in the address info array. if ( false !== $index && empty( $posted_data[ $post_key ] ) && ! $info[ $info_key ] ) { $fields[ $index ]['required'] = false; } } }
Expand full source code Collapse full source code View on GitHub
Changelog Changelog
Version | Description |
---|---|
5.0.0 | Introduced. |