Skip to content

Paypal Buttons with WordPress Custom Templates

2011 November 7
by Kathy Alice
  • Facebook
  • Twitter
  • Delicious
  • LinkedIn
  • StumbleUpon
  • Add to favorites
  • Email
  • RSS

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.

WordPress custom post templateAn 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.

Paypal Profile Selling Tools

Select Shipping Calculations in Your Paypal Profile's Selling Tools

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.

Paypal drop down menu

Paypal Drop Down menu for different sizes and prices

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.

  1. 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.
  2. 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.php file 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”.
  3. 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
    */
    ?>
  4. 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.
  5. 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.

Connect:

Kathy Alice

Kathy Alice Brown is a technologist, author, blogger and SEO consultant with a background in web operations and engineering.In her spare time she loves to get outside.
Connect:

Latest posts by Kathy Alice (see all)

Share and Enjoy

5 Responses Post a comment
  1. November 15, 2011

    I really liked your blog! It helped me alot… Awesome. Exactly what I was looking for. Thanks!

  2. February 13, 2013

    Thanks for the detailed notes on using custom template in WordPress.

    I am currently using Yoast SEO in the blog. Will there be any conflict in using this custom template and Yoast ?

    Did you find any issues? Please reply your thoughts.

    Thanks again.

    • Kathy Alice permalink*
      March 4, 2013

      I haven’t seen any issues with custom templates and Yoast.

  3. laura permalink
    March 13, 2013

    In step 4 above, where exactly do you add the paypal code? I’ve tried a few variations (saving a backup copy before I made changes each time) but have not been able to get this to work. I had to deactivate the plugin but still want to make this work.

    • Kathy Alice permalink*
      March 17, 2013

      I don’t have access to the site or the files anymore – but I put the Paypal code directly into the template file that I uploaded to the server. My guess is that I put it after the_content() function call.

Leave a Reply

Note: You may use basic HTML in your comments. Your email address will not be published.

Subscribe to this comment feed via RSS

Email
Print