Stripe Payment Gateway Integration in WordPress Without Plugin (2026 Guide)

Published

Looking for a Stripe payment gateway integration in WordPress without a plugin? You can do it with either a no-code Payment Link or a small piece of code in your child theme. This guide shows both, step by step, so you avoid plugin bloat and keep full control of your checkout. Fees for the examples are covered in our guide to how much Stripe charges per transaction.

Why Add Stripe to WordPress Without a Plugin?

Payment plugins add convenience, but also extra code to update, extra attack surface and sometimes extra fees. A plugin-free Stripe payment gateway integration keeps the site lightweight and lets you design the exact flow you want. The trade-off is that you maintain the code yourself, so use a child theme, keep keys out of the theme files and test in Stripe's test mode first.

How to Integrate Stripe Payment Gateway in WordPress: Two Methods

MethodCode neededBest for
Payment Link buttonNoneA few products, services or donations
Stripe Checkout + child-theme endpointAbout 60 lines of PHPCustom prices, order handling, webhooks

Method 1: Stripe Payment Link in WordPress (No Code)

  1. In the Stripe Dashboard open Payment Links and create a link for your product and price.
  2. Copy the link, which looks like https://buy.stripe.com/....
  3. In the WordPress block editor add a Button block and paste the link as the button URL.

Customers pay on a Stripe-hosted page, so card details never touch your site. The limit is that you get little control over carts and custom order records.

Method 2: Stripe Checkout in WordPress With a Custom Endpoint

This creates a Checkout Session on your server and redirects the buyer to Stripe's hosted payment page. The session must be created server-side because it needs your secret key, which can never appear in browser code. Stripe recommends the Checkout Sessions API for most new integrations.

Step 1: Add the Stripe PHP library

Download the latest stripe-php release from GitHub (or run composer require stripe/stripe-php) and upload it to your child theme, for example /wp-content/themes/your-child-theme/stripe-php/.

Step 2: Store your keys in wp-config.php

define( 'STRIPE_SECRET_KEY', 'sk_test_xxx' );
define( 'STRIPE_WEBHOOK_SECRET', 'whsec_xxx' );

Step 3: Add the endpoints to functions.php

<?php
require_once get_stylesheet_directory() . '/stripe-php/init.php';

add_action( 'rest_api_init', function () {
  register_rest_route( 'mysite/v1', '/checkout', array(
    'methods'             => 'POST',
    'callback'            => 'mysite_create_checkout',
    'permission_callback' => '__return_true',
  ) );
  register_rest_route( 'mysite/v1', '/stripe-webhook', array(
    'methods'             => 'POST',
    'callback'            => 'mysite_stripe_webhook',
    'permission_callback' => '__return_true',
  ) );
} );

function mysite_create_checkout() {
  $stripe = new \Stripe\StripeClient( STRIPE_SECRET_KEY );
  // The price is set on the server. Never trust an amount sent from the browser.
  $session = $stripe->checkout->sessions->create( array(
    'mode'        => 'payment',
    'line_items'  => array( array(
      'price_data' => array(
        'currency'     => 'usd',
        'product_data' => array( 'name' => 'Website Audit' ),
        'unit_amount'  => 4900, // $49.00 in cents
      ),
      'quantity' => 1,
    ) ),
    'success_url' => home_url( '/thank-you/?session_id={CHECKOUT_SESSION_ID}' ),
    'cancel_url'  => home_url( '/pricing/' ),
  ) );
  return array( 'url' => $session->url );
}

function mysite_stripe_webhook( WP_REST_Request $request ) {
  try {
    $event = \Stripe\Webhook::constructEvent(
      $request->get_body(),
      $request->get_header( 'stripe-signature' ),
      STRIPE_WEBHOOK_SECRET
    );
  } catch ( \Exception $e ) {
    return new WP_REST_Response( array( 'error' => 'Invalid signature' ), 400 );
  }
  if ( 'checkout.session.completed' === $event->type ) {
    $session = $event->data->object;
    // Fulfil the order here: send an email, grant access, save to the database.
  }
  return new WP_REST_Response( array( 'received' => true ), 200 );
}

Step 4: Add the Pay button to a page

Paste this into a Custom HTML block on the page where you want the button:

<button id="pay-btn">Pay $49</button>
<script>
document.getElementById('pay-btn').addEventListener('click', async () => {
  const res  = await fetch('/wp-json/mysite/v1/checkout', { method: 'POST' });
  const data = await res.json();
  window.location = data.url; // redirect to Stripe Checkout
});
</script>

Step 5: Create the webhook in Stripe

In the Dashboard go to Developers > Webhooks, add https://yoursite.com/wp-json/mysite/v1/stripe-webhook and subscribe to checkout.session.completed. Fulfil orders from the webhook, not the thank-you page, because buyers can close the tab before reaching it.

Security Checklist for a Plugin-Free Stripe Integration

  • Use a child theme, otherwise a theme update erases your code.
  • Keep sk_ keys in wp-config.php and out of Git.
  • Always verify the webhook signature, as the code above does.
  • Set prices on the server, never from a form field.
  • Test with card 4242 4242 4242 4242, then switch to live keys and run one small real payment.

What Will Stripe Charge You?

Stripe's standard US price is 2.9% + 30¢ per domestic card payment, so a $49 sale costs $1.72 and you keep $47.28. Run your own numbers in our Stripe fee calculator.

Related Guides

Frequently Asked Questions

Can I add Stripe to WordPress without a plugin?

Yes. Use a Stripe Payment Link button for no code, or create a Checkout Session from a small endpoint in your child theme and redirect the customer to Stripe.

Is Stripe safe to use without a plugin?

Yes, if card details stay on Stripe's hosted page, your secret key stays server-side and you verify webhook signatures.

Do I need WooCommerce for Stripe?

No. Payment Links and the custom Checkout endpoint above work on any WordPress site without WooCommerce.

Sources

Educational use only. Not financial advice. FeeCalculatorBuzz is not affiliated with Stripe, Venmo or Toast. Fees change, so confirm current rates on the provider's official pricing page before you set prices.