How to sell products on the website via PayPal

Okay, there are two payment options:

I think the second way is absolutely better because it works without you — you can snowboarding or be asleep at this time :)

So, how to make it work?

Step 1. Everything begins with a form

That’s your payment form, more information about PayPal form parameters you can find here and here.

<form action="" method="post">
	<input type="hidden" name="cmd" value="_xclick">
	<!-- The PayPal account to pay -->
	<input type="hidden" name="business" id="business" value="YOUR PAYPAL EMAIL HERE" />
	<!-- Amount price -->
	<input type="hidden" name="amount" id="amount" value="9.00" />
	<!-- It will be shown on PayPal checkout page -->
	<input type="hidden" name="item_name" id="item_name" value="ITEM NAME" />
	<!-- Specify your product ID here to process it later -->
	<input type="hidden" name="item_number" id="item_number" value="1038" />
	<!-- Charset -->
	<input type="hidden" name="charset" value="utf-8">
	<!-- Thank You page, the customer will be redirected after the payment -->
	<input type="hidden" name="return" value="">
	<button>Buy Now</button> 

Paypal IPN (Instant payment notifications) mechanism

Step 2. The IPN settings

Scroll Summary page to the bottom to find Seller Preferences link.
On the Seller Preferences page find «Instant Payment Notifications»
Specify your notification URL here.

Step 3. The code

The last step is to process PayPal notifications. This is the content of /shop/paypal.php file.

$r = array(
    'status' => $_POST['payment_status'],
    'payer_email'      => $_POST['payer_email']
if( isset( $_POST['item_number'] ) ) {
	$r['item_number'] = intval($_POST['item_number']);
} elseif ( isset( $_POST['item_number1'] ) ) {
	$r['item_number'] = intval($_POST['item_number1']);
if( strtolower( $_POST['payment_status'] ) == 'completed' && $r['item_number'] ) {
	 * On success - do some stuff here, you can:
	 * register new user
	 * send the product by email
	 * redirect customer to a product page
	 * etc
// uncomment the following lines if you want to receive the debug message each time
// $headers  = "Content-type: text/html; charset=utf-8 \r\n"; 
// $headers .= "From: paypal.php <>\r\n";
// $msg = print_r($_POST, true);
// mail("", 'IPN debug message', $msg, $headers);
Misha Rudrastyh

Misha Rudrastyh

Hey guys and welcome to my website. For more than 10 years I've been doing my best to share with you some superb WordPress guides and tips for free.

Need some developer help? Contact me

Follow me on X