Add Paypal Button programmatically

You can create a custom template in the theme that displays the ‘products’ custom post types (see the section on Template Files in Custom Post Types).

Then code the HTML for the Paypal button in to your specific single-{posttype}.php and have the attributes such as price, etc, coming from custom fields.

<form target="paypal" action="https://www.paypal.com/cgi-bin/webscr" method="post">
<input type="hidden" name="cmd" value="_cart">
<input type="hidden" name="business" value="[email protected]">
<input type="hidden" name="lc" value="GB">
<input type="hidden" name="item_name" value="<?php $meta_values = get_post_meta($post_id, 'product-name'); ?>">
<input type="hidden" name="item_number" value="<?php $meta_values = get_post_meta($post_id, 'product-reference'); ?>">
<input type="hidden" name="amount" value="<?php $meta_values = get_post_meta($post_id, 'product-value'); ?>">
<input type="hidden" name="currency_code" value="GBP">
<input type="hidden" name="button_subtype" value="products">
<input type="hidden" name="no_note" value="0">
<input type="hidden" name="add" value="1">
<input type="hidden" name="bn" value="PP-ShopCartBF:btn_cart_LG.gif:NonHostedGuest">
<input type="image" src="https://www.paypalobjects.com/en_GB/i/btn/btn_cart_LG.gif" border="0" name="submit" alt="PayPal — The safer, easier way to pay online.">
<img alt="" border="0" src="https://www.paypalobjects.com/en_GB/i/scr/pixel.gif" width="1" height="1">
</form>

(I think that is correct but it’s been a while since I’ve played with custom fields so apologies if it needs further tweaking)

P.S – Although, are you sure you want to use Paypal’s own cart? It would be more graceful to use a shopping cart plugin for WordPress (which you can use with your own theme) then have the total value go through to Paypal when the customer is ready to pay (probably an obvious thing to say but just thought I’d mention it in case :))