Skip to content

Commit

Permalink
Only include digital and physical products in payment lines name.
Browse files Browse the repository at this point in the history
  • Loading branch information
rvdsteege committed Jun 6, 2024
1 parent dc45e1a commit 8b5c384
Show file tree
Hide file tree
Showing 2 changed files with 18 additions and 5 deletions.
13 changes: 10 additions & 3 deletions src/Payments/PaymentLines.php
Original file line number Diff line number Diff line change
Expand Up @@ -60,18 +60,25 @@ public function get_array() {

/**
* Get name.
*
*
* @link https://github.com/pronamic/wp-pronamic-pay-woocommerce/issues/43
* @param array|null $types Which payment line types to include.
* @return string
*/
public function get_name() {
public function get_name( $types = null ) {
$names = \array_map(
function ( PaymentLine $line ) {
function ( PaymentLine $line ) use ( $types ) {
if ( null !== $types && ! \in_array( $line->get_type(), $types ) ) {
return;
}

return (string) $line->get_name();
},
$this->get_array()
);

$names = \array_filter( $names );

return \implode( ', ', $names );
}

Expand Down
10 changes: 8 additions & 2 deletions src/Payments/PaymentMergeTagsController.php
Original file line number Diff line number Diff line change
Expand Up @@ -12,14 +12,15 @@

use Pronamic\WordPress\Pay\MergeTags\MergeTagsController;
use Pronamic\WordPress\Pay\MergeTags\MergeTag;
use Pronamic\WordPress\Pay\Payments\PaymentLineType;

/**
* Payment Merge Tags Controller class
*/
class PaymentMergeTagsController extends MergeTagsController {
/**
* Construct payment merge tags controllers.
*
*
* @param Payment $payment Payment.
*/
public function __construct( Payment $payment ) {
Expand Down Expand Up @@ -51,7 +52,12 @@ function () use ( $payment ) {
return '';
}

return $lines->get_name();
$types = [
PaymentLineType::DIGITAL,
PaymentLineType::PHYSICAL,
];

return $lines->get_name( $types );
}
)
);
Expand Down

0 comments on commit 8b5c384

Please sign in to comment.