resources
11 months ago
DonationHistoryWidget.php
1 year ago
DonationReceiptWidget.php
1 year ago
GiveDonorWallWidget.php
1 year ago
GiveFormGridWidget.php
11 months ago
GiveFormWidget.php
11 months ago
GiveGoalWidget.php
1 year ago
GiveLoginWidget.php
1 year ago
GiveMultiFormGoalWidget.php
1 year ago
GiveProfileEditorWidget.php
1 year ago
GiveRegisterWidget.php
1 year ago
GiveSubscriptionsWidget.php
1 year ago
GiveTotalsWidget.php
1 year ago
DonationReceiptWidget.php
422 lines
| 1 | <?php |
| 2 | |
| 3 | namespace Give\ThirdPartySupport\Elementor\Widgets\V1; |
| 4 | |
| 5 | use Elementor\Widget_Base; |
| 6 | |
| 7 | /** |
| 8 | * Elementor Donation Receipt Widget. |
| 9 | * |
| 10 | * Elementor widget that inserts the GiveWP [give_receipt] shortcode to output a donor's full Donation Receipt table. |
| 11 | * |
| 12 | * @since 4.7.0 migrated from givewp-elementor-widgets |
| 13 | */ |
| 14 | |
| 15 | class DonationReceiptWidget extends Widget_Base |
| 16 | { |
| 17 | /** |
| 18 | * Get widget name. |
| 19 | * |
| 20 | * Retrieve Donation Receipt widget name. |
| 21 | * |
| 22 | * @since 4.7.0 migrated from givewp-elementor-widgets |
| 23 | * @access public |
| 24 | * |
| 25 | * @return string Widget name. |
| 26 | */ |
| 27 | public function get_name() |
| 28 | { |
| 29 | return 'Donation Receipt'; |
| 30 | } |
| 31 | |
| 32 | /** |
| 33 | * Get widget title. |
| 34 | * |
| 35 | * Retrieve Donation Receipt widget title. |
| 36 | * |
| 37 | * @since 4.7.0 migrated from givewp-elementor-widgets |
| 38 | * @access public |
| 39 | * |
| 40 | * @return string Widget title. |
| 41 | */ |
| 42 | public function get_title() |
| 43 | { |
| 44 | return __('Give Donation Receipt (Legacy)', 'give'); |
| 45 | } |
| 46 | |
| 47 | /** |
| 48 | * Get widget icon. |
| 49 | * |
| 50 | * Retrieve Donation Receipt widget icon. |
| 51 | * |
| 52 | * @since 4.7.0 migrated from givewp-elementor-widgets |
| 53 | * @access public |
| 54 | * |
| 55 | * @return string Widget icon. |
| 56 | */ |
| 57 | public function get_icon() |
| 58 | { |
| 59 | return 'give-icon'; |
| 60 | } |
| 61 | |
| 62 | /** |
| 63 | * Get widget categories. |
| 64 | * |
| 65 | * Retrieve the list of categories the Donation Receipt widget belongs to. |
| 66 | * |
| 67 | * @since 4.7.0 migrated from givewp-elementor-widgets |
| 68 | * @access public |
| 69 | * |
| 70 | * @return array Widget categories. |
| 71 | */ |
| 72 | public function get_categories() |
| 73 | { |
| 74 | return ['givewp-category-legacy']; |
| 75 | } |
| 76 | |
| 77 | /** |
| 78 | * Widget inner wrapper. |
| 79 | * |
| 80 | * Use optimized DOM structure, without the inner wrapper. |
| 81 | * |
| 82 | * @since 4.7.0 migrated from givewp-elementor-widgets |
| 83 | * @access public |
| 84 | */ |
| 85 | public function has_widget_inner_wrapper(): bool |
| 86 | { |
| 87 | return false; |
| 88 | } |
| 89 | |
| 90 | /** |
| 91 | * Register Donation Receipt widget controls. |
| 92 | * |
| 93 | * Adds different input fields to allow the user to change and customize the widget settings. |
| 94 | * |
| 95 | * @since 4.7.0 migrated from givewp-elementor-widgets |
| 96 | * @access protected |
| 97 | */ |
| 98 | protected function register_controls() |
| 99 | { |
| 100 | $this->start_controls_section( |
| 101 | 'content_section', |
| 102 | [ |
| 103 | 'label' => __('GiveWP Donation Receipt Widget', 'give'), |
| 104 | 'tab' => \Elementor\Controls_Manager::TAB_CONTENT, |
| 105 | ] |
| 106 | ); |
| 107 | |
| 108 | $this->add_control( |
| 109 | 'error', |
| 110 | [ |
| 111 | 'label' => __('Error Message', 'give'), |
| 112 | 'type' => \Elementor\Controls_Manager::TEXTAREA, |
| 113 | 'description' => __('Custom text to show if there is an error showing the receipt table.', 'give'), |
| 114 | 'default' => __('You are missing the donation id to view this donation receipt.', 'give'), |
| 115 | 'placeholder' => __('You are missing the donation id to view this donation receipt.', 'give'), |
| 116 | ] |
| 117 | ); |
| 118 | |
| 119 | $this->add_control( |
| 120 | 'success', |
| 121 | [ |
| 122 | 'label' => __('Success Message', 'give'), |
| 123 | 'type' => \Elementor\Controls_Manager::TEXTAREA, |
| 124 | 'description' => __('Custom text to show if the donation was successful.', 'give'), |
| 125 | 'default' => __('Thank you for your donation.', 'give'), |
| 126 | 'placeholder' => __('Thank you for your donation.', 'give'), |
| 127 | ] |
| 128 | ); |
| 129 | |
| 130 | $this->add_control( |
| 131 | 'price', |
| 132 | [ |
| 133 | 'label' => __('Donation Total', 'give'), |
| 134 | 'type' => \Elementor\Controls_Manager::SWITCHER, |
| 135 | 'description' => __('Show or hide a row with the total donation amount.', 'give'), |
| 136 | 'label_on' => __('Show', 'give'), |
| 137 | 'label_off' => __('Hide', 'give'), |
| 138 | 'default' => 'yes' |
| 139 | ] |
| 140 | ); |
| 141 | |
| 142 | $this->add_control( |
| 143 | 'donor', |
| 144 | [ |
| 145 | 'label' => __('Donor', 'give'), |
| 146 | 'type' => \Elementor\Controls_Manager::SWITCHER, |
| 147 | 'description' => __('Show or hide a row with the donors full name.', 'give'), |
| 148 | 'label_on' => __('Show', 'give'), |
| 149 | 'label_off' => __('Hide', 'give'), |
| 150 | 'default' => 'yes' |
| 151 | ] |
| 152 | ); |
| 153 | |
| 154 | $this->add_control( |
| 155 | 'date', |
| 156 | [ |
| 157 | 'label' => __('Date', 'give'), |
| 158 | 'type' => \Elementor\Controls_Manager::SWITCHER, |
| 159 | 'description' => __('Show or hide a row with the date of the donation.', 'give'), |
| 160 | 'label_on' => __('Show', 'give'), |
| 161 | 'label_off' => __('Hide', 'give'), |
| 162 | 'default' => 'yes' |
| 163 | ] |
| 164 | ); |
| 165 | |
| 166 | $this->add_control( |
| 167 | 'method', |
| 168 | [ |
| 169 | 'label' => __('Payment Method', 'give'), |
| 170 | 'type' => \Elementor\Controls_Manager::SWITCHER, |
| 171 | 'description' => __('Show or hide a row with the name of the payment type (credit card, offline, etc).', 'give'), |
| 172 | 'label_on' => __('Show', 'give'), |
| 173 | 'label_off' => __('Hide', 'give'), |
| 174 | 'default' => 'yes' |
| 175 | ] |
| 176 | ); |
| 177 | |
| 178 | $this->add_control( |
| 179 | 'payment_id', |
| 180 | [ |
| 181 | 'label' => __('Payment ID', 'give'), |
| 182 | 'type' => \Elementor\Controls_Manager::SWITCHER, |
| 183 | 'description' => __('Show or hide a row with the ID of the donation.', 'give'), |
| 184 | 'label_on' => __('Show', 'give'), |
| 185 | 'label_off' => __('Hide', 'give'), |
| 186 | 'default' => 'yes' |
| 187 | ] |
| 188 | ); |
| 189 | |
| 190 | $this->add_control( |
| 191 | 'status', |
| 192 | [ |
| 193 | 'label' => __('Status', 'give'), |
| 194 | 'type' => \Elementor\Controls_Manager::SWITCHER, |
| 195 | 'description' => __('Show or hide a row with the status of the payment.', 'give'), |
| 196 | 'label_on' => __('Show', 'give'), |
| 197 | 'label_off' => __('Hide', 'give'), |
| 198 | 'default' => 'no' |
| 199 | ] |
| 200 | ); |
| 201 | |
| 202 | $this->add_control( |
| 203 | 'company', |
| 204 | [ |
| 205 | 'label' => __('Company Name', 'give'), |
| 206 | 'type' => \Elementor\Controls_Manager::SWITCHER, |
| 207 | 'description' => __('Show or hide a row with the company name the donor provided.', 'give'), |
| 208 | 'label_on' => __('Show', 'give'), |
| 209 | 'label_off' => __('Hide', 'give'), |
| 210 | 'default' => 'no' |
| 211 | ] |
| 212 | ); |
| 213 | |
| 214 | $this->add_control( |
| 215 | 'status_notice', |
| 216 | [ |
| 217 | 'label' => __('Payment Status Notice', 'give'), |
| 218 | 'type' => \Elementor\Controls_Manager::SWITCHER, |
| 219 | 'description' => __('Show or hide an alert above the receipt table showing the status of the donation payment.', 'give'), |
| 220 | 'label_on' => __('Show', 'give'), |
| 221 | 'label_off' => __('Hide', 'give'), |
| 222 | 'default' => 'yes' |
| 223 | ] |
| 224 | ); |
| 225 | |
| 226 | $this->add_control( |
| 227 | 'give_receipt_info', |
| 228 | [ |
| 229 | 'label' => '', |
| 230 | 'type' => \Elementor\Controls_Manager::RAW_HTML, |
| 231 | 'content_classes' => 'give-info', |
| 232 | 'raw' => ' |
| 233 | <div class="give"> |
| 234 | <p class="info-head"> |
| 235 | ' . __('GIVEWP RECEIPT WIDGET', 'give') . '</p> |
| 236 | <p class="info-message">' . __('This is the GiveWP Receipt widget. Choose the columns you want to have appear for your donor receipts.', 'give') . '</p> |
| 237 | <p class="info-message"><strong>' . __('NOTE:', 'give') . '</strong> ' . __('This is a sample receipt with all fields exposed. The alerts and info will show correctly for your donors. This receipt is just for preview/editing purposes.', 'give') . '</p> |
| 238 | <p class="give-docs-links"> |
| 239 | <a href="https://givewp.com/documentation/core/shortcodes/give_receipt/?utm_source=plugin_settings&utm_medium=referral&utm_campaign=Free_Addons&utm_content=givelementor" rel="noopener noreferrer" target="_blank"><i class="fa fa-book" aria-hidden="true"></i>' . __('Visit the GiveWP Docs for more info on the GiveWP Donation Receipt.', 'give') . '</a> |
| 240 | </p> |
| 241 | </div>' |
| 242 | ] |
| 243 | ); |
| 244 | |
| 245 | $this->end_controls_section(); |
| 246 | } |
| 247 | |
| 248 | /** |
| 249 | * Render the [give_receipt] output on the frontend. |
| 250 | * |
| 251 | * Written in PHP and used to generate the final HTML. |
| 252 | * |
| 253 | * @since 4.7.0 migrated from givewp-elementor-widgets |
| 254 | * @access protected |
| 255 | */ |
| 256 | protected function render() |
| 257 | { |
| 258 | $settings = $this->get_settings_for_display(); |
| 259 | |
| 260 | $error = esc_html($settings['error']); |
| 261 | $success = esc_html($settings['success']); |
| 262 | $price = ('yes' === $settings['price'] ? '' : 'price="false"'); |
| 263 | $donor = ('yes' === $settings['donor'] ? '' : 'donor="false"'); |
| 264 | $date = ('yes' === $settings['date'] ? '' : 'date="false"'); |
| 265 | $method = ('yes' === $settings['method'] ? '' : 'payment_method="false"'); |
| 266 | $id = ('yes' === $settings['payment_id'] ? '' : 'payment_id="false"'); |
| 267 | $status = ('yes' === $settings['status'] ? 'payment_status="true"' : ''); |
| 268 | $company = ('yes' === $settings['company'] ? 'company_name="true"' : ''); |
| 269 | $notice = ('yes' === $settings['status_notice'] ? '' : 'status_notice="false"'); |
| 270 | |
| 271 | // Add-on compatibility |
| 272 | // Adding PDF Receipt row, and Subscription table |
| 273 | $pdfreceipts = (class_exists('Give_PDF_Receipts')) ? "true" : "false"; |
| 274 | $recurring = (class_exists('Give_Recurring')) ? "true" : "false"; |
| 275 | |
| 276 | if (!\Elementor\Plugin::$instance->editor->is_edit_mode()) { |
| 277 | $html = do_shortcode(' |
| 278 | [give_receipt ' |
| 279 | . $error . ' ' |
| 280 | . $price . ' ' |
| 281 | . $donor . ' ' |
| 282 | . $date . ' ' |
| 283 | . $method . ' ' |
| 284 | . $id . ' ' |
| 285 | . $status . ' ' |
| 286 | . $company . ' ' |
| 287 | . $notice . |
| 288 | ']' |
| 289 | ); |
| 290 | |
| 291 | echo '<div class="givewp-elementor-widget give_receipt">'; |
| 292 | |
| 293 | echo $html; |
| 294 | |
| 295 | echo '</div>'; |
| 296 | } else { |
| 297 | ?> |
| 298 | <div id="give-receipt"> |
| 299 | <div class="give_notices give_errors" id="give_error_fail"> |
| 300 | <p class="give_notice give_error"> |
| 301 | <?php echo (!empty($error) ? $error : __('You are missing the donation ID to view this donation receipt.', 'give')); ?> |
| 302 | </p> |
| 303 | </div> |
| 304 | <?php if ('yes' == $settings['status_notice']) : ?> |
| 305 | <div class="give_notices give_errors" id="give_error_success"> |
| 306 | <p class="give_notice give_success"> |
| 307 | <?php echo (!empty($success) ? $success : __('Thank you for your donation.', 'give')); ?> |
| 308 | </p> |
| 309 | </div> |
| 310 | <?php endif; ?> |
| 311 | <table id="give_donation_receipt" class="give-table"> |
| 312 | <thead> |
| 313 | <tr> |
| 314 | <th scope="colgroup" colspan="2"> |
| 315 | <span class="give-receipt-thead-text"><?php _e('Donation Receipt', 'give'); ?></span> |
| 316 | </th> |
| 317 | </tr> |
| 318 | </thead> |
| 319 | |
| 320 | <tbody> |
| 321 | <?php |
| 322 | if ('yes' == $settings['donor']) : ?> |
| 323 | <tr> |
| 324 | <td scope="row"><strong><?php _e('Donor', 'give'); ?></strong></td> |
| 325 | <td><?php _e('Test Donor', 'give'); ?></td> |
| 326 | </tr> |
| 327 | <?php endif; |
| 328 | if ('yes' == $settings['company']) : ?> |
| 329 | <tr> |
| 330 | <td scope="row"><strong><?php _e('Company Name', 'give') ;?></strong></td> |
| 331 | <td>Impress.org</td> |
| 332 | </tr> |
| 333 | <?php endif; |
| 334 | if ('yes' == $settings['date']) : ?> |
| 335 | <tr> |
| 336 | <td scope="row"><strong><?php _e('Date', 'give'); ?></strong></td> |
| 337 | <td><?php _e('April 18, 2020' , 'give') ;?></td> |
| 338 | </tr> |
| 339 | <?php endif; |
| 340 | if ('yes' == $settings['price']) : ?> |
| 341 | <tr> |
| 342 | <td scope="row"><strong><?php _e('Total Donation' ,'give'); ?></strong></td> |
| 343 | <td>$25.00</td> |
| 344 | </tr> |
| 345 | <?php endif; ?> |
| 346 | <tr> |
| 347 | <td scope="row"><strong><?php _e('Donation' , 'give'); ?></strong></td> |
| 348 | <td><?php _e('First Form', 'give'); ?><span class="donation-level-text-wrap"></span></td> |
| 349 | </tr> |
| 350 | <?php |
| 351 | if ('yes' == $settings['status']) : ?> |
| 352 | <tr> |
| 353 | <td scope="row"><strong><?php _e('Donation Status', 'give'); ?></strong></td> |
| 354 | <td><?php _e('Complete', 'give'); ?></td> |
| 355 | </tr> |
| 356 | <?php endif; |
| 357 | if ('yes' == $settings['payment_id']) : ?> |
| 358 | <tr> |
| 359 | <td scope="row"><strong><?php _e('Donation ID', 'give');?></strong></td> |
| 360 | <td>3</td> |
| 361 | </tr> |
| 362 | <?php endif; |
| 363 | if ('yes' == $settings['method']) : ?> |
| 364 | <tr> |
| 365 | <td scope="row"><strong><?php _e('Payment Method' , 'give'); ?></strong></td> |
| 366 | <td><?php _e('Test Donation', 'give'); ?></td> |
| 367 | </tr> |
| 368 | <?php endif; |
| 369 | if ('true' == $pdfreceipts) : ?> |
| 370 | <tr> |
| 371 | <td><strong><?php _e('Receipt', 'give'); ?>:</strong></td> |
| 372 | <td><a class="give_receipt_link" title="Download Receipt" href="#"><?php _e('Download Receipt', 'give');?> »</a></td> |
| 373 | </tr> |
| 374 | <?php endif;?> |
| 375 | </tbody> |
| 376 | </table> |
| 377 | |
| 378 | <?php if ('true' == $recurring) : ?> |
| 379 | <table id="give-subscription-receipt" class="give-table"> |
| 380 | |
| 381 | <thead> |
| 382 | <tr> |
| 383 | <th scope="colgroup" colspan="2"> |
| 384 | <span class="give-receipt-thead-text"><?php _e('Subscription Details', 'give'); ?></span> |
| 385 | </th> |
| 386 | </tr> |
| 387 | </thead> |
| 388 | |
| 389 | <tbody> |
| 390 | |
| 391 | <tr> |
| 392 | <td scope="row"><strong><?php _e('Subscription:', 'give'); ?></strong></td> |
| 393 | <td> |
| 394 | <span class="give-subscription-billing-cycle">$25.00 / <?php _e('Monthly', 'give'); ?></span> |
| 395 | </td> |
| 396 | </tr> |
| 397 | <tr> |
| 398 | <td scope="row"><strong><?php _e('Status:', 'give'); ?></strong></td> |
| 399 | <td> |
| 400 | <span class="give-subscription-status"><span class="give-donation-status status-active"><span class="give-donation-status-icon"></span> <?php _e('Active', 'give'); ?></span></span> |
| 401 | </td> |
| 402 | </tr> |
| 403 | <tr> |
| 404 | <td scope="row"><strong><?php _e('Renewal Date:', 'give'); ?></strong></td> |
| 405 | <td><span class="give-subscription-renewal-date"><?php _e('June 4, 2020', 'give'); ?></span></td> |
| 406 | </tr> |
| 407 | <tr> |
| 408 | <td scope="row"><strong><?php _e('Progress:', 'give'); ?></strong></td> |
| 409 | <td><span class="give-subscription-times-billed">1 / <?php _e('Ongoing', 'give'); ?></span> |
| 410 | </td> |
| 411 | </tr> |
| 412 | |
| 413 | </tbody> |
| 414 | </table> |
| 415 | <a href="#" class="give-recurring-manage-subscriptions-receipt-link"><?php _e('Manage Subscriptions', 'give'); ?> »</a> |
| 416 | </div> |
| 417 | <?php |
| 418 | endif; // End if Recurring Donations is active. |
| 419 | } |
| 420 | } |
| 421 | } |
| 422 |