Getting to Know Woo: Extending Payment Gateway Options in WooCommerce

Co-written by @ralucastn and @nielslange


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:

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.


Keep yourself in the loop!

This field is hidden when viewing the form
This field is hidden when viewing the form
This field is hidden when viewing the form


One response to “Getting to Know Woo: Extending Payment Gateway Options in WooCommerce”

  1. Brian Henry Avatar
    Brian Henry

    I have a plugin for duplicating payment gateway, which are then filtered based on cart contents. E.g. I can duplicate the Cash App gateway and the money is sent to one person if product A is sold, and the other person for product B.

    https://github.com/BrianHenryIE/bh-wc-duplicate-payment-gateways

    Unfortunately, it doesn’t work with all payment gateways. In particular, where the WC_Payment_Gateway’s $id property is set inside the constructor rather than being just set on the class. Where it’s set on the class, I can extend and override the value before the duplicate object is constructed.

    Similarly, I’m seeing where it will be more difficult to duplicate gateways that use the Blocks Checkout.

    It would be good if documentation were to discourage developers from hard-coding the gateway id in their JavaScript.

Leave a Reply

Your email address will not be published. Required fields are marked *