|
14 | 14 | exit;
|
15 | 15 | }
|
16 | 16 |
|
| 17 | +/** |
| 18 | + * Filters new address settings into the settings general endpoint |
| 19 | + * |
| 20 | + * These new settings are being added to WC 3.x in |
| 21 | + * pull request https://github.com/woocommerce/woocommerce/pull/15636 |
| 22 | + * This filter is used to insert them if not present. |
| 23 | + * |
| 24 | + * THIS FILTER SHOULD NOT BE PORTED TO WOOCOMMERCE CORE as the above PR |
| 25 | + * already takes care of this in WooCommerce core. |
| 26 | + */ |
| 27 | +function wc_rest_dev_add_address_settings_to_settings_general( $settings ) { |
| 28 | + $new_settings = array( |
| 29 | + array( |
| 30 | + 'id' => 'woocommerce_store_address', |
| 31 | + 'type' => 'text', |
| 32 | + 'option_key' => 'woocommerce_store_address', |
| 33 | + 'default' => '', |
| 34 | + ), |
| 35 | + array( |
| 36 | + 'id' => 'woocommerce_store_address_2', |
| 37 | + 'type' => 'text', |
| 38 | + 'option_key' => 'woocommerce_store_address_2', |
| 39 | + 'default' => '', |
| 40 | + ), |
| 41 | + array( |
| 42 | + 'id' => 'woocommerce_store_city', |
| 43 | + 'type' => 'text', |
| 44 | + 'option_key' => 'woocommerce_store_city', |
| 45 | + 'default' => '', |
| 46 | + ), |
| 47 | + array( |
| 48 | + 'id' => 'woocommerce_store_postcode', |
| 49 | + 'type' => 'text', |
| 50 | + 'option_key' => 'woocommerce_store_postcode', |
| 51 | + 'default' => '', |
| 52 | + ), |
| 53 | + ); |
| 54 | + |
| 55 | + // For each of the new settings, make sure the setting id doesn't |
| 56 | + // already exist in the settings array and then add it |
| 57 | + $ids = array_column( $settings, 'id' ); |
| 58 | + foreach ( $new_settings as $new_setting ) { |
| 59 | + if ( ! in_array( $new_setting['id'], $ids ) ) { |
| 60 | + $settings[] = $new_setting; |
| 61 | + } |
| 62 | + } |
| 63 | + |
| 64 | + return $settings; |
| 65 | +} |
| 66 | +add_filter( 'woocommerce_settings-general', 'wc_rest_dev_add_address_settings_to_settings_general', 999 ); |
| 67 | + |
17 | 68 | /**
|
18 | 69 | * REST API Setting Options controller class.
|
19 | 70 | *
|
|
0 commit comments