Skip to content

Commit

Permalink
address review feedback
Browse files Browse the repository at this point in the history
  • Loading branch information
senadir committed Feb 29, 2024
1 parent 02e09e0 commit fe334f0
Show file tree
Hide file tree
Showing 3 changed files with 9 additions and 25 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -99,7 +99,7 @@ public function capture_order_confirmation_view() {
$checkout_page_used = 'No';
}

$fields_data = $this->get_additional_fields_data( $order );
$fields_data = $this->get_additional_fields_data();

$data = array(
'coupon_used' => $coupon_used,
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -577,11 +577,9 @@ public function post_contains_text( $post_id, $text ) {
/**
* Get additional fields data for Checkout and Post-Checkout events.
*
* @param WC_Order|null $order The order object or null if we don't have an order.
*
* return array An array containing the additional fields data.
* @return array Additional fields data.
*/
private function get_additional_fields_data( $order = null ) {
private function get_additional_fields_data() {
$data = array();

if ( class_exists( 'Automattic\WooCommerce\Blocks\Package' ) && class_exists( 'Automattic\WooCommerce\Blocks\Domain\Services\CheckoutFields' ) ) {
Expand All @@ -591,31 +589,17 @@ private function get_additional_fields_data( $order = null ) {
$fields_data = array_map(
function ( $field_key, $field ) use ( $additional_fields_controller ) {
return array(
$field_key,
$additional_fields_controller->get_field_location( $field_key ),
$field['type'],
$field['required'] ? '1' : '0',
'key' => $field_key,
'location' => $additional_fields_controller->get_field_location( $field_key ),
'type' => $field['type'],
'required' => $field['required'] ? '1' : '0',
'label' => $field['label'],
);
},
array_keys( $additional_fields ),
$additional_fields
);

if ( $order ) {
$fields_data = array_map(
function ( $field ) use ( $additional_fields_controller, $order ) {
// For additional and contact, they have the default group, which is ''.
$field_group = $field[1] === 'address' ? 'shipping' : '';
$field[] = $additional_fields_controller->get_field_from_order( $field[0], $order, $field_group );
// If we have no value in shipping, try billing.
if ( $field[1] === 'address' && ! $field[4] ) {
$field[4] = $additional_fields_controller->get_field_from_order( $field[0], $order, 'billing' );
}
return $field;
},
$fields_data
);
}
$data = array(
'fields_count' => $fields_count,
'fields' => wp_json_encode( $fields_data ),
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -347,7 +347,7 @@ public function order_process( $order_id ) {
$checkout_page_contains_checkout_shortcode = '1';
}

$fields_data = $this->get_additional_fields_data( $order );
$fields_data = $this->get_additional_fields_data();

// loop through products in the order and queue a purchase event.
foreach ( $order->get_items() as $order_item ) {
Expand Down

0 comments on commit fe334f0

Please sign in to comment.