Skip to content

Commit

Permalink
Add method to get payment method field by identifier.
Browse files Browse the repository at this point in the history
  • Loading branch information
rvdsteege committed Aug 11, 2022
1 parent f21d102 commit 93b251b
Showing 1 changed file with 23 additions and 0 deletions.
23 changes: 23 additions & 0 deletions src/Core/PaymentMethod.php
Original file line number Diff line number Diff line change
Expand Up @@ -113,4 +113,27 @@ public function add_field( Field $field ) {
public function get_fields() {
return $this->fields;
}

/**
* Get field by identifier.
*
* @param string $id Field identifier.
* @return Field|null
*/
public function get_field( $id ) : ?Field {
$fields = array_filter(
$this->get_fields(),
function( $field ) use ( $id ) {
return $field->get_id() === $id;
}
);

$field = reset( $fields );

if ( false !== $field ) {
return $field;
}

return null;
}
}

0 comments on commit 93b251b

Please sign in to comment.