Co-written by @ralucastn and @nielslange
This is chapter 4 of 5 in the series Getting to Know Woo: A Series on the Cart and Checkout Blocks
In this series, we’ve learned how to add new content and how to modify existing content when it comes to the Cart and Checkout blocks, but there’s an important aspect of this part of the product that requires its own mention. Extensibility on the Payment gateways side has been one of our most important focuses, and we have been writing about it in the past.
In this post, we will look at two of the ways we can add and modify the payment methods visible in the checkout.
The Payment Method API
We offer an extensive Payment Method API for you to integrate a payment gateway or an express payment gateway like WooCommerce Pay, Stripe, PayPal, Square. If you’re curious how a gateway extension like Stripe adds its integration, you can check out this pull request.
Checkout the documentation for the Payment Method API for more detailed information.
Filtering Payment Methods
Separate from the Payment Method API, you can also filter out payment methods. For the cases where some payment gateways don’t fit your product type (for example subscriptions, bookings, etc.) or you want to add special conditions to certain payment gateways we offer two APIs:
- To filter targeted and individual payment gateways, use registerPaymentMethodExtensionCallbacks
- To filter all payments gateways that don’t support a certain feature, use register_payment_requirements, currently undocumented, but this is a demo of how to use it.
Next Stop: Exploring Server-Side Extensibility with Hooks
Our final installment of the series will focus on extensibility on the server side. In the next post, we will show you the available action and filter hooks. This may be more familiar to developer who are familiar with traditional PHP action and filter hooks.
In the meantime, if you have any questions during the integration process, our recommendation is to reach out on our GitHub Discussions section Q&A โ Extension Integrations and Customizations or in the Community Slack #woocommerce-blocks-and-block-themes channel.
Leave a Reply