I received the following question from a user today:
When users create a charity on my site, I want to have a donate button on their post that automatically gets the proper email address to use for the PayPal transaction. This way I don’t have to manually add their email to the shortcode for every charity that is created on my site.
This is a quick tutorial for users who want to create a PayPal payment button widget in the blog posts using the author’s PayPal email address. This way the payment or donation directly goes to the post author’s PayPal account. Here is how to do it:
Step 1
Grab the free WP PayPal Payment Plugin and install it (if you don’t have it installed already). This plugin lets you crate payment widgets to accept PayPal payment.
Step 2
Open your theme’s functions.php file and add the following snippet of code:
add_filter('wppp_widget_email', 'custom_payment_widget_email'); function custom_payment_widget_email($email){ $email = get_the_author_meta('user_email'); return $email; } add_filter('wppp_widget_any_amt_email', 'custom_payment_any_amt_widget_email'); function custom_payment_any_amt_widget_email($email){ $email = get_the_author_meta('user_email'); return $email; }
The above code will override the PayPal email address value of the payment widget with the post author’s email address automatically.
Step 3
Now, you can use the shortcodes offered by the PayPal payment widget plugin to place a payment widget anywhere inside the WordPress post or you can add the widget from your theme’s template file.
Below is an example of what you could add in your theme’s template file to create the payment widget (the “email” parameter will be auto populated when the page renders):
<?php echo do_shortcode('[wp_paypal_payment_box email="" options="Payment 1:15.50|Payment 2:30.00|Payment 3:50.00"]'); ?>
Note:Â You can also add custom author meta to store the user’s PayPal email address then modify the code in step 2 to use that value (instead of the default email address value).
Leave a Reply