Created
November 19, 2018 17:04
-
-
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.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| <?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