Code Examples
This collection of code examples addresses the most common customization requests we receive through support. Each example includes complete, tested code that you can copy directly into your WordPress site, along with clear explanations of what the code does and where to implement it.
Adding Custom Code Safely
We recommend using the Code Snippets plugin when adding custom code to your site. It's easier than modifying your theme's functions.php
file and much safer since your customizations won't be lost when you update your theme.
The Code Snippets plugin provides:
- A user-friendly interface for managing code snippets
- Syntax highlighting and error detection
- Easy activation/deactivation of code snippets
- Protection from theme updates
- Organized snippet management
Browse Examples
📄️ Conditional Payment Authorization
When processing payments, you might want to handle certain orders differently based on specific criteria. For example, high-value orders might require manual review before charging the customer, while standard orders can be processed immediately. This code sample shows how to automatically authorize (but not capture) payments when the order total exceeds a certain threshold.
📄️ Customize Metadata
When processing payments through Stripe, you may want to include additional information about the order, customer, or transaction context. Stripe allows you to attach custom metadata to payment intents, which can be invaluable for tracking, reporting, and debugging purposes. This metadata appears in your Stripe Dashboard and can be used for analytics or integration with other systems.
📄️ Customize Payment Form
The default Stripe payment form is designed to work seamlessly with most websites, but you might want to customize its appearance to better match your brand or design requirements. This code sample shows how to modify the visual styling of the Stripe payment form using Stripe's appearance API, including colors, fonts, spacing, and other design elements.
📄️ Force Save Payment Method
Some businesses need to collect payment information during checkout but charge the customer's payment method at a later time. This is particularly common for merchants with long fulfillment timelines, custom manufacturing processes, or complex supply chains where products aren't immediately available for shipping.
📄️ Increasing Authorization Amount
When you authorize a payment instead of capturing it immediately, you might discover that you need to charge more than the original order total before capturing the funds. Perhaps you need to add rush shipping, include additional items the customer requested, or apply fees that weren't calculated at checkout. However, Stripe prevents you from capturing more than the originally authorized amount for security reasons.
📄️ Add Billing Address
Some merchants prefer to streamline their checkout process by consolidating billing information directly within the payment form rather than displaying separate billing fields on the checkout page. This approach can reduce form complexity and provide a more cohesive payment experience by keeping all payment-related information in one location.
📄️ Remove Mandate Text
When customers choose to save their payment method during checkout, Stripe displays mandate text that explains the terms for future charges. This text appears as legal language informing customers that they're authorizing your business to charge their saved payment method according to your terms. While this provides transparency, some merchants prefer a cleaner checkout experience without this additional text.