Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Only include digital and physical products in payment lines name. #185

Closed
Closed
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
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
Loading