AI Verified

Name

PayPal-Donation

Language

PHP

Rating

Voted: 1 by 1 user(s)

Codevault

WebSquadron

Scroll down to see more snippets from this codevault.

Wordpress Compatability

The author has indicated that this snippet is compatable up to wordpress version: 6.4

Our AI bot has checked this snippet is compatable up to wordpress version: 6.1

Code Snippet Plugin Sync

Free & Pro

Download this snippet by clicking the download button, then head over to the Code Snippet Plugin settings in your wordpress admin dashboard, select the import menu then upload this file to import into your wordpress site.

Pro Only (Coming Soon)

You will be able to click a button and sync this snippet to your wordpress site automatically and from your dashboard manage all code snippets across all your wordpress sites that have the Code Snippets Pro plugin installed.

History

Last modified:

16/02/2024

Important Note

This snippet has the following status:

AI Verified

This snippet has been tested by our AI bot, see any comments below.

AI Bot Comments:

Found 0 vulnerabilities

PayPal-Donation

 
                    
1/*
2Generated by Imran Siddiq Web Squadron with ChatGPT
3 
4Example Shortcodes to use;
51. Donate with no currency or price stated
62. Donate with £GBP currency but no price stated
73. Donate with $USD Currency and $50 stated
84. Donate with $USD Currency and $50, $100, $150 stated
9 
101. [donate]
112. [donate currency="GBP"]
123. [donate currency="USD" amount="50"]
134. [donate currency="USD" options="50,100,150"]
14*/
15 
16function donate_shortcode($atts, $content = null) {
17 global $post;
18 $atts = shortcode_atts(array(
19 'account' => 'example@gmail.com',
20 'for' => get_the_title($post),
21 'onHover' => '',
22 'currency' => 'GBP', // Default currency
23 'amount' => '', // Default amount, leaving empty for user input or a specific value
24 'options' => '' // Possible amounts, separated by commas (e.g., "50,100,150")
25 ), $atts);
26 
27 $account = esc_attr($atts['account']);
28 $for = urlencode('Donation for ' . $atts['for']);
29 $onHover = esc_attr($atts['onHover']);
30 $currency = esc_attr($atts['currency']);
31 $amount = esc_attr($atts['amount']);
32 $options = esc_attr($atts['options']);
33 $content = $content ?: 'Make A Payment';
34 
35 // Handling donation amount options
36 if (!empty($options)) {
37 $optionsList = explode(',', $options);
38 $link = 'https://www.paypal.com/donate?business=' . $account . '&currency_code=' . $currency . '&item_name=' . $for;
39 // If options exist, generate dropdown or buttons for each specified amount
40 $donationForm = '<form action="' . esc_url($link) . '" method="post" target="_top">';
41 foreach ($optionsList as $option) {
42 $donationForm .= '<input type="radio" name="amount" value="' . esc_attr($option) . '"> $' . esc_html($option) . '<br>';
43 }
44 $donationForm .= '<input type="submit" value="' . esc_attr($content) . '" title="' . $onHover . '">';
45 $donationForm .= '</form>';
46 return $donationForm;
47 } else {
48 $link = 'https://www.paypal.com/cgi-bin/webscr?cmd=_xclick&business=' . $account . '&currency_code=' . $currency . '&amount=' . $amount . '&item_name=' . $for;
49 return '<a href="' . esc_url($link) . '" title="' . $onHover . '">' . esc_html($content) . '</a>';
50 }
51}
52add_shortcode('donate', 'donate_shortcode');

1

Related Snippets

Please see some snippets below related to this snippet..

General

AI Verified

0

Save Gravity Forms Stripe Payment Methods to Stripe Customers

Added: 9 months ago

Last Updated: 9 months ago

<p>https://docs.gravityforms.com/gform_stripe_charge_pre_create/#h-2-attach-payment-method-to-the-customer</p> <p>https://docs.gravityforms.com/gform_stripe_payment_element_initial_payment_information...

General

Unverified

0

Highlight-Text

Added: 1 month ago

Last Updated: 1 month ago

Highlight Text within a Text Editor or a Heading

General

AI Verified

0

Gravity to Stripe Description

Added: 9 months ago

Last Updated: 8 months ago

Other Snippets in this Codevault

These are some popular snippets from this users codevault..

Performance

AI Verified

32

Remove Unused Javascript

Added: 1 year ago

Last Updated: 3 days ago

Remove Unused Javascript - and improve your Page Speed Insight Score

WooCommerce

Pro Verified

10

Deactivate some WooCommerce Checkout Fields

Added: 1 year ago

Last Updated: 2 weeks ago

Deactivate some WooCommerce Checkout Fields from showing

Elementor

AI Verified

6

CSS Grid Aid

Added: 8 months ago

Last Updated: 1 month ago

This can be used for any WordPress Builder to aid working with CSS Grids.