|
2 | 2 |
|
3 | 3 | namespace BitCode\FI\Core\Util; |
4 | 4 |
|
| 5 | +use BitCode\FI\Triggers\TriggerController; |
5 | 6 | use DateTime; |
| 7 | +use DateTimeZone; |
| 8 | +use Exception; |
6 | 9 | use stdClass; |
7 | 10 | use WP_Error; |
8 | | -use Exception; |
9 | | -use DateTimeZone; |
10 | | -use BitCode\FI\Triggers\TriggerController; |
11 | 11 |
|
12 | 12 | /** |
13 | 13 | * bit-integration helper class |
@@ -299,6 +299,72 @@ public static function acfGetFieldGroups($type = []) |
299 | 299 | }); |
300 | 300 | } |
301 | 301 |
|
| 302 | + public static function getAcfFieldData($acfFieldGroups, $postId) |
| 303 | + { |
| 304 | + if (!class_exists('ACF')) { |
| 305 | + return []; |
| 306 | + } |
| 307 | + |
| 308 | + $data = []; |
| 309 | + |
| 310 | + foreach ($acfFieldGroups as $group) { |
| 311 | + foreach (acf_get_fields($group['ID']) as $field) { |
| 312 | + $data[$field['_name']] = get_post_meta($postId, $field['_name'])[0]; |
| 313 | + } |
| 314 | + } |
| 315 | + |
| 316 | + return $data; |
| 317 | + } |
| 318 | + |
| 319 | + public static function getWCCustomCheckoutData($order) |
| 320 | + { |
| 321 | + if (!class_exists('WooCommerce')) { |
| 322 | + return []; |
| 323 | + } |
| 324 | + |
| 325 | + $data = []; |
| 326 | + $order = \is_object($order) ? (array) $order : $order; |
| 327 | + $checkoutFields = WC()->checkout()->get_checkout_fields(); |
| 328 | + |
| 329 | + foreach ($checkoutFields as $group) { |
| 330 | + foreach ($group as $field) { |
| 331 | + if (!empty($field['custom'])) { |
| 332 | + $data[$field['name']] = $order[$field['name']]; |
| 333 | + } |
| 334 | + } |
| 335 | + } |
| 336 | + |
| 337 | + return $data; |
| 338 | + } |
| 339 | + |
| 340 | + public static function getFlexibleCheckoutData($order) |
| 341 | + { |
| 342 | + if (!class_exists('WooCommerce')) { |
| 343 | + return []; |
| 344 | + } |
| 345 | + |
| 346 | + $data = []; |
| 347 | + $order = \is_object($order) ? (array) $order : $order; |
| 348 | + $checkoutFields = WC()->checkout()->get_checkout_fields(); |
| 349 | + |
| 350 | + foreach ($checkoutFields as $groupKey => $group) { |
| 351 | + if ($groupKey == 'shipping') { |
| 352 | + continue; |
| 353 | + } |
| 354 | + |
| 355 | + foreach ($group as $fieldKey => $field) { |
| 356 | + if (empty($field['custom_field'])) { |
| 357 | + continue; |
| 358 | + } |
| 359 | + |
| 360 | + $fieldKey = $field['name'] ?? $fieldKey; |
| 361 | + $data[$fieldKey] = $order[$fieldKey] ?? ''; |
| 362 | + } |
| 363 | + } |
| 364 | + |
| 365 | + return $data; |
| 366 | + } |
| 367 | + |
302 | 368 | public static function isPrimaryKeysMatch($recordData, $PrimaryKeys) |
303 | 369 | { |
304 | 370 | foreach ($PrimaryKeys as $primaryKey) { |
|
0 commit comments