Paypal Buttons with WordPress Custom Templates
WordPress templates are powerful tools. For example many themes use templates to give you the option of creating a sales page without the sidebar. But I had never seen these custom templates used for WordPress posts.
An artist needed Paypal buttons added to her WordPress site, a portfolio of paintings and prints showcased using posts. But at this point we only wanted to add Paypal buttons for the prints, which were available at a the same range of prices based on size of the print and the paper used. Since most of the posts (but not all) would have the same Paypal buttons, I wanted to find a way to avoid copying and pasting code onto each page. I also wanted to empower my client to have the choice to “turn on” or choose the paypal buttons with just a click or two. I found the answer in WordPress custom post templates.
The power of Paypal Profiles
But first a few words about Paypal. You can get pretty far with Paypal for your eCommerce needs. Not only can you configure buttons with multiple choice drop down lists for an item but you also have a lot of control over shipping rates and taxes. Both domestic and international options are available for Paypal Business Accounts.
Here are some of the options you have through Paypal Merchant Services:
- State pick list for configuring taxes charged for individual states. So you can only charge taxes buyers that live in the same state as your business.
- State pick list for setting up differing shipping rates.
- Ability to set differing shipping rates based on weight or price of item. For example above $100 you charge $2 more for shipping and handling.
What’s even nicer is that you can set up these options as a default in your “Profile” under Shipping Tools. Then when you create the buttons you can either override the settings or just let it use the settings from the profile.
Once the profile was in place, I set up two “Add to Cart” buttons, each with three options: small, medium, large. I needed the second one to offer the option of getting the print on metallic paper which was slightly more expensive. Once the code is generated you can copy and paste the code to WordPress.
WordPress Custom Post Templates
Now that we have the Paypal button code, the next step is to set up a custom post template file in WordPress.
- First install the custom post template plug-in. This adds a selection widget (see above) to the lower right of the post editing screen that allows the writer to select the template they wish to use with the post. At first there won’t be any templates to select, that gets addressed in the next steps. The plug-in description is helpful reading although a bit terse.
- Next you will need to create a new file in your WordPress installation. This requires you to be able to create and edit a .php file and upload it to your server. What I did is download and make a copy of the
single.phpfile which is what WordPress uses to display a single post. Your new filename needs to end with the word “Posts”. In my case I called it “paypalPosts.php”.
- Add the following code to the top of your new template file, replacing YOURTEMPLATENAME with the name of your template.
<?php /* Template Name Posts: YOURTEMPLATENAME */ ?>
- Finally make the changes that you want in this template but not in the default template. In my case I added the Paypal button code.
- Upload the file to your WordPress installation, now you should be able to go to any post and select either the default template or your new template.
The reason I like this solution so much is that now when the artist wants to upload a new print onto her site, she can just select the the Paypal template to add the Paypal buttons to the new post without calling me.
Latest posts by Kathy Alice (see all)
- Moving WordPress to a New Domain in 7 Steps - July 21, 2015
- Is WiX SEO Friendly? - April 9, 2015
- Do You Need to Worry about SEO with WishList Member? - March 12, 2015