Skip to content

Instantly share code, notes, and snippets.

Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save rvdsteege/3636b8375e9de5247d14b6dfca77b687 to your computer and use it in GitHub Desktop.
Save rvdsteege/3636b8375e9de5247d14b6dfca77b687 to your computer and use it in GitHub Desktop.
Custom payment description tags with Pronamic Pay.
<?php
/**
* Pronamic Pay payment description tags.
*
* @param \Pronamic\WordPress\Pay\Payments\Payment $payment $payment Payment.
* @return void
*/
function pronamic_pay_description_tags( $payment ) {
// Customer.
$customer_name = '';
$customer = $payment->get_customer();
if ( null !== $customer ) {
$customer_name = strval( $customer->get_name() );
}
// Items.
$items = [];
$lines = $payment->get_lines();
if ( null !== $lines ) {
$items = array_map(
function ( \Pronamic\WordPress\Pay\Payments\PaymentLine $line ) {
return $line->get_name();
},
$lines->get_array()
);
}
// Replace tags in description.
$replacements = [
'{customer:name}' => $customer_name,
'{items}' => implode( ', ', $items ),
];
$description = strtr( $payment->get_description(), $replacements );
$payment->set_description( $description );
}
add_action( 'pronamic_pay_pre_create_payment', 'pronamic_pay_description_tags' );
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment