Stripe Checkout Subscription is a WordPress plugin that provides membership subscription functionality using Stripe Checkout. It stores subscription data (like invoice details, last payment date, etc.) in user meta, supports daily cron checks to maintain user roles, and comes with an intuitive admin interface for managing subscriptions.
Note: Currently I'm including the whole stripe PHP SDK folder in ./stripe but we should move to composer. This is a legacy from my existing application. It's a simple fix I just haven't got around to implementing it.
- Features
- Requirements
- Installation
- Configuration
- Usage
- Admin Area
- Shortcodes
- Troubleshooting
- Contributing
- License
- Stripe Checkout Integration: Redirects users to Stripe’s hosted checkout pages for streamlined subscription purchases.
- Webhook Handling: Uses WP REST endpoints to handle events like
checkout.session.completed
and invoice events (invoice.paid
,invoice.payment_succeeded
). - Membership Role Assignment: Automatically assigns a configurable “premium” (or other) role upon successful payment.
- Daily Subscription Checks: Removes premium roles after a configurable time period (default 30 days) with no payment.
- Custom Admin Interface: Provides a dedicated admin menu for subscription management, plus a settings page to configure API keys and URLs.
- No Hard-Coding: All sensitive or site-specific data (Stripe keys, webhook secrets, role names, success/cancel URLs) is managed via a WordPress settings page.
- WordPress 4.9+ (recommended 5.0+).
- PHP 7.2+ (recommended 7.4+ or 8+).
- A Stripe account and your secret key and webhook signing secret.
- Composer or manual installation of Stripe PHP library if modifying the plugin code (the plugin ships with
stripe-php
included instripe/init.php
).
-
Download or Clone
- Download the plugin
.zip
file from your preferred source or clone the repo if you’re developing.
- Download the plugin
-
Upload to WordPress
- Log into your WordPress admin area, go to Plugins → Add New, and upload the
.zip
file OR - Upload the plugin folder to your
/wp-content/plugins/
directory manually.
- Log into your WordPress admin area, go to Plugins → Add New, and upload the
-
Activate
- In Plugins, find Stripe Checkout Subscription and click Activate.
-
Permalinks
- If necessary, go to Settings → Permalinks and click Save Changes to ensure custom rewrite rules for checkout endpoints are flushed.
After activating, navigate to Subscriptions → Settings in your WordPress admin menu. Here you can:
-
Stripe Secret Key
- Your live or test secret key (e.g.,
sk_live_********
orsk_test_********
).
- Your live or test secret key (e.g.,
-
Webhook Signing Secret
- A signing secret generated by Stripe to validate webhook requests. When Debug Mode is disabled, signature verification is enforced.
-
Success/Cancel URLs
- Set the return URLs for both your standard WordPress site flow and any external “app” flow.
- If left blank, the plugin falls back to default URLs (e.g.
home_url('/checkout-success?session_id={CHECKOUT_SESSION_ID}')
).
-
Portal Return URL
- The return URL for Stripe’s customer billing portal if using an external app environment.
-
Premium Role Name
- Define the role to be assigned upon successful payments (defaults to
premium_member
).
- Define the role to be assigned upon successful payments (defaults to
-
Debug Mode
- If enabled, the plugin will skip webhook signature verification (useful for local testing). Make sure to disable in production!
After saving your configuration, you’re ready to set up Stripe webhooks (see Usage below).
To ensure your site receives invoice updates and checkout session completions, add a webhook endpoint in your Stripe Dashboard:
- URL:
https://yoursite.com/wp-json/stripe/v1/webhook
(replaceyoursite.com
with your actual domain). - Events: Typically
checkout.session.completed
,invoice.payment_succeeded
, andinvoice.paid
. - Signing Secret: Copy this from Stripe and place it in the plugin settings as Webhook Signing Secret.
You can create links of the form:
https://yoursite.com/checkout/<USER_ID>/<PLAN>
where <PLAN>
corresponds to a plan_slug
in your code that maps to an actual Stripe Price ID. By default, the plugin’s plan lookup function uses 'monthly' => 'price_XXX'
, but you can modify or extend that in the plugin code if desired.
- A logged-in user visits
/checkout/<user_id>/<plan>
- The user is redirected to Stripe Checkout for payment.
- On success, Stripe redirects back to the Success URL (configurable).
- Webhook events update the user’s meta to record subscription details and assign the “premium” role.
You’ll find two new items in your Subscriptions menu:
-
Subscriptions (main page)
- Lists all users (or filters by “Active,” “Expired,” “All”).
- Shows each user’s subscription status, last payment date, and next renewal date (approx).
- Actions:
- Free Renewal: Manually extends a user’s subscription by updating
last_payment_date
. - Create Free Sub: Assigns the premium role and/or a
free_trial
role to the user, useful for testing or complimentary access.
- Free Renewal: Manually extends a user’s subscription by updating
-
Settings
- The config page described above for your Stripe keys, webhook secret, URLs, role name, and debug mode.
The plugin includes optional shortcodes:
-
[sps_checkout_link plan="monthly"]
- Displays a button or link that sends the current logged-in user to
/checkout/<user_id>/monthly
.
- Displays a button or link that sends the current logged-in user to
-
[sps_manage_link]
- Displays a link to
/manage-subscription/<user_id>
for the logged-in user to view their Stripe Billing Portal (if configured).
- Displays a link to
Feel free to customize the link/plan slug in your theme or plugin code.
-
Webhook Signature Verification Fails
- Verify you copied the signing secret from Stripe exactly.
- If Debug Mode is enabled, signature checks are skipped—disable for production.
-
No Premium Role Assigned
- Make sure you have specified a valid role name in the Premium Role Name setting.
- Check if your user meta fields (
stripe_subscription_id
,stripe_customer_id
, etc.) are being updated.
-
Cron Not Working
- WordPress crons rely on site traffic; ensure there is site traffic or consider using a real cron job (e.g., WP-CLI cron).
- The plugin only removes premium role if no payment is recorded in the last 30 days (configurable in code).
-
Test Mode vs. Live Mode
- Keep in mind you have separate secret keys, signing secrets, and webhooks for Test vs. Live in Stripe. Double-check you’re using the correct ones.
- Pull Requests are welcome if you want to add new features, optimize code, or fix bugs.
- Issues can be opened for any problems you encounter or enhancements you suggest.
- Development: If you’re modifying the plugin extensively, ensure you test locally or on a staging environment. You might also run
composer install
to manage Stripe’s PHP library if updating dependencies.
Thank you for using Stripe Checkout Subscription! We hope it simplifies your membership or subscription needs. If you have questions or feedback, feel free to open an issue or submit a pull request. Enjoy!