PluginProbe
SureCart – Ecommerce Made Easy For Selling Physical Products, Digital Downloads, Subscriptions, Donations, & Payments / 4.4.1
SureCart – Ecommerce Made Easy For Selling Physical Products, Digital Downloads, Subscriptions, Donations, & Payments v4.4.1
4.7.2 4.7.1 4.7.0 4.6.6 4.6.5 4.6.4 4.6.3 4.6.2 4.6.1 4.6.0 4.5.1 4.5.0 4.4.2 4.4.1 4.4.0 4.3.3 4.3.2 4.3.1 4.3.0 4.2.3 4.2.2 4.2.1 1.0.3 1.0.4 1.0.5 All 281 releases
surecart / app / src / Abilities / Concerns / MapsGenericAddress.php
MapsGenericAddress.php
33 lines 909 B
No matching file
Up and down to move Enter to open Esc to close
Raw Download Zip
1 <?php
2
3 namespace SureCart\Abilities\Concerns;
4
5 /**
6 * Maps generic `{prefix}_*` address fields from ability input into a nested address
7 * array (`city`, `country`, `line_1`, …) for the SureCart API.
8 */
9 trait MapsGenericAddress {
10
11 /**
12 * Map prefixed address keys in ability input to a nested address array.
13 *
14 * @param array $input The input data.
15 * @param string $prefix The key prefix without trailing underscore (e.g. `shipping_address`).
16 *
17 * @return array
18 */
19 protected function map_generic_address( array $input, string $prefix ): array {
20 $address = array();
21 $address_fields = array( 'city', 'country', 'line_1', 'line_2', 'postal_code', 'state' );
22
23 foreach ( $address_fields as $key ) {
24 $input_key = $prefix . '_' . $key;
25 if ( ! empty( $input[ $input_key ] ) ) {
26 $address[ $key ] = sanitize_text_field( $input[ $input_key ] );
27 }
28 }
29
30 return $address;
31 }
32 }
33