File tree Expand file tree Collapse file tree 1 file changed +27
-0
lines changed
sample-code-snippets/misc Expand file tree Collapse file tree 1 file changed +27
-0
lines changed Original file line number Diff line number Diff line change 1+ <?php
2+
3+ /**
4+ * Mailchimp always expects a full and complete address when you use a field of type "address"
5+ *
6+ * This snippet will allow you to submit a partial address and fill missing fields with fallback values.
7+ * Fill sensible fallback data for your region, especially ZIP might expect a different value depending on your locale.
8+ */
9+
10+ add_filter ('mc4wp_format_field_value ' , function ($ value , $ field_type ) {
11+ if ($ field_type === 'address ' ) {
12+ $ value = is_array ($ value ) ? $ value : [];
13+
14+ $ fallbacks = [
15+ 'addr1 ' => 'N/A ' ,
16+ 'city ' => 'N/A ' ,
17+ 'state ' => 'N/A ' ,
18+ 'zip ' => '00000 ' ,
19+ ];
20+
21+ // Fill missing values from fallbacks
22+ foreach ($ fallbacks as $ k => $ fallback ) {
23+ $ value [$ k ] = isset ($ value [$ k ]) && $ value [$ k ] !== '' ? $ value [$ k ] : $ fallback ;
24+ }
25+ }
26+ return $ value ;
27+ }, 10 , 2 );
You can’t perform that action at this time.
0 commit comments