From 8b5c3845ba2bbb518a93cb88a8c5b672589c6d17 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Re=C3=BCel=20van=20der=20Steege?= Date: Thu, 6 Jun 2024 09:42:23 +0200 Subject: [PATCH] Only include digital and physical products in payment lines name. --- src/Payments/PaymentLines.php | 13 ++++++++++--- src/Payments/PaymentMergeTagsController.php | 10 ++++++++-- 2 files changed, 18 insertions(+), 5 deletions(-) diff --git a/src/Payments/PaymentLines.php b/src/Payments/PaymentLines.php index dab7a93a..5143fe68 100644 --- a/src/Payments/PaymentLines.php +++ b/src/Payments/PaymentLines.php @@ -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 ); } diff --git a/src/Payments/PaymentMergeTagsController.php b/src/Payments/PaymentMergeTagsController.php index d3318f3e..a17974c3 100644 --- a/src/Payments/PaymentMergeTagsController.php +++ b/src/Payments/PaymentMergeTagsController.php @@ -12,6 +12,7 @@ use Pronamic\WordPress\Pay\MergeTags\MergeTagsController; use Pronamic\WordPress\Pay\MergeTags\MergeTag; +use Pronamic\WordPress\Pay\Payments\PaymentLineType; /** * Payment Merge Tags Controller class @@ -19,7 +20,7 @@ class PaymentMergeTagsController extends MergeTagsController { /** * Construct payment merge tags controllers. - * + * * @param Payment $payment Payment. */ public function __construct( Payment $payment ) { @@ -51,7 +52,12 @@ function () use ( $payment ) { return ''; } - return $lines->get_name(); + $types = [ + PaymentLineType::DIGITAL, + PaymentLineType::PHYSICAL, + ]; + + return $lines->get_name( $types ); } ) );