PluginProbe
GiveWP – Donation Plugin and Fundraising Platform / 4.16.8.1
GiveWP – Donation Plugin and Fundraising Platform v4.16.8.1
4.16.9 4.16.8.1 4.16.8 4.16.7.2 4.16.7.1 4.16.7 4.16.6.1 4.16.6 4.16.5.1 4.16.5 4.16.4 4.16.3 4.16.2 4.16.1 4.16.0 4.15.5 4.15.4 4.15.3 4.15.2 4.15.1 4.15.0 2.3.0 2.3.1 2.3.2 2.30.0 All 255 releases
give / src / Form / LegacyConsumer / Commands / SetupFieldReceipt.php

SetupFieldReceipt.php in GiveWP – Donation Plugin and Fundraising Platform 4.16.8.1, at src/Form/LegacyConsumer/Commands/SetupFieldReceipt.php

111 lines 2.5 KB
No matching file
Up and down to move Enter to open Esc to close
Raw Download Zip
1 <?php
2
3 namespace Give\Form\LegacyConsumer\Commands;
4
5 use Give\Framework\FieldsAPI\Field;
6 use Give\Framework\FieldsAPI\Group;
7 use Give\Receipt\DonationReceipt;
8
9 /**
10 * @since 2.10.2
11 */
12 class SetupFieldReceipt
13 {
14 /**
15 * @var DonationReceipt
16 */
17 protected $receipt;
18
19 /**
20 * @since 2.10.2
21 *
22 * @param DonationReceipt $receipt
23 */
24 public function __construct(DonationReceipt $receipt)
25 {
26 $this->receipt = $receipt;
27 }
28
29 /**
30 * @since 2.10.2
31 *
32 * @param string $hook
33 *
34 * @return void
35 */
36 public function __invoke($hook)
37 {
38 $formID = give_get_payment_meta($this->receipt->donationId, '_give_payment_form_id');
39
40 $collection = Group::make($hook);
41 do_action("give_fields_{$hook}", $collection, $formID);
42
43 $collection->walkFields([$this, 'apply']);
44 }
45
46 /**
47 * @since 2.10.2
48 *
49 * @param Field $field
50 *
51 * @return void
52 */
53 public function apply(Field $field)
54 {
55 if ( ! $field->shouldShowInReceipt()) {
56 return;
57 }
58
59 if ($field->shouldStoreAsDonorMeta()) {
60 $this->addDonorLineItem($field);
61 } else {
62 $this->addAdditionalLineItems($field);
63 }
64 }
65
66 /**
67 * @since 2.10.2
68 *
69 * @param Field $field
70 *
71 * @return void
72 */
73 protected function addDonorLineItem(Field $field)
74 {
75 $donorID = give_get_payment_meta($this->receipt->donationId, '_give_payment_donor_id');
76 if ($value = Give()->donor_meta->get_meta($donorID, $field->getName(), true)) {
77 $this->receipt
78 ->getSections()[DonationReceipt::DONORSECTIONID]
79 ->addLineItem(
80 [
81 'id' => $field->getName(),
82 'label' => $field->getLabel(),
83 'value' => $value,
84 ]
85 );
86 }
87 }
88
89 /**
90 * @since 2.10.2
91 *
92 * @param Field $field
93 *
94 * @return void
95 */
96 protected function addAdditionalLineItems(Field $field)
97 {
98 if ($value = give_get_payment_meta($this->receipt->donationId, $field->getName())) {
99 $this->receipt
100 ->getSections()[DonationReceipt::ADDITIONALINFORMATIONSECTIONID]
101 ->addLineItem(
102 [
103 'id' => $field->getName(),
104 'label' => $field->getLabel(),
105 'value' => $value,
106 ]
107 );
108 }
109 }
110 }
111