Skip to content

Instantly share code, notes, and snippets.

@joshfeck
Created November 19, 2018 17:04
Show Gist options
  • Select an option

  • Save joshfeck/70f3b1311c85b417aa73f501f69e8b6f to your computer and use it in GitHub Desktop.

Select an option

Save joshfeck/70f3b1311c85b417aa73f501f69e8b6f to your computer and use it in GitHub Desktop.
Send a comma separated list of line items (truncates the end of the line item name to return 25 characters) when there's a promotion code on the transaction. Event Espresso 4, PayPal Pro gateway.
<?php
//* Please do NOT include the opening php tag, except of course if you're starting with a blank file
add_filter(
'EEG_Paypal_Pro__do_direct_payment__partial_amount_line_item_name',
'my_custom_paypal_pro_line_items_with_promotions',
10,
3
);
function my_custom_paypal_pro_line_items_with_promotions(
$string,
$object,
$payment
) {
$transaction = $payment->transaction();
if (! $transaction instanceof EE_Transaction) {
return $string;
}
$total_line_item = $transaction->total_line_item();
if (! $total_line_item instanceof EE_Line_Item) {
return $string;
}
$order_items = array();
foreach ($total_line_item->get_items() as $line_item) {
// ignore line items with a quantity of 0
if ($line_item->quantity() == 0) {
continue;
}
$item = substr(
$line_item->name(),
0,
25
);
array_push($order_items, $item);
}
$string = implode(",", $order_items);
return $string;
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment