Get Custom Payment Gateway Data As Settings In Woocommerce 3

WooCommerce Docs

Documentation, Reference Materials, and Tutorials for your WooCommerce products

Payment Gateway API

Payment gateways in WooCommerce are class based and can be added through traditional plugins. This guide provides an intro to gateway development.

Types of payment gateway ↑ Back to top

Payment gateways come in several varieties:

  1. Form based– This is where the user must click a button on a form that then redirects them to the payment processor on the gateway’s own website. Example: PayPal standard, DPM
  2. iFrame based– This is when the gateway payment system is loaded inside an iframe on your store. Example: SagePay Form, PayPal Advanced
  3. Direct– This is when the payment fields are shown directly on the checkout page and the payment is made when ‘place order’ is pressed. Example: PayPal Pro, AIM
  4. Offline– No online payment is made. Example: Cheque, Bank Transfer

Form and iFrame based gateways post data offsite, meaning there are less security issues for you to think about. Direct gateways, however, require server security to be implemented (SSL certificates, etc.) and may also require a level of PCI compliance.

Creating a basic payment gateway ↑ Back to top

Payment gateways should be created as additional plugins that hook into WooCommerce. Inside the plugin, you need to create a class after plugins are loaded. Example:

It is also important that your gateway class extends the WooCommerce base gateway class, so you have access to important methods and the settings API:

As well as defining your class, you need to also tell WooCommerce (WC) that it exists. Do this by filtering woocommerce_payment_gateways:

Required Methods ↑ Back to top

Most methods are inherited from the WC_Payment_Gateway class, but some are required in your custom gateway.

Within your constructor, you should define the following variables:

  • $this->id – Unique ID for your gateway, e.g., ‘your_gateway’
  • $this->icon – If you want to show an image next to the gateway’s name on the frontend, enter a URL to an image.
  • $this->has_fields – Bool. Can be set to true if you want payment fields to show on the checkout (if doing a direct integration).
  • $this->method_title – Title of the payment method shown on the admin page.
  • $this->method_description – Description for the payment method shown on the admin page.

Your constructor should also define and load settings fields:

We’ll cover init_form_fields() later, but this basically defines your settings that are then loaded with init_settings() .

After init_settings() is called, you can get the settings and load them into variables, meaning:

Finally, you need to add a save hook for your settings:

Use this method to set $this->form_fields – these are options you’ll show in admin on your gateway settings page and make use of the WC Settings API.

A basic set of settings for your gateway would consist of enabled, titleand description:

process_payment( $order_id )
Now for the most important part of the gateway — handling payment and processing the order. Process_payment also tells WC where to redirect the user, and this is done with a returned array.

Here is an example of a process_payment function from the Cheque gateway:

As you can see, its job is to:

  • Get and update the order being processed
  • Reduce stock and empty the cart
  • Return success and redirect URL (in this case the thanks page)

Cheque gives the order On-Hold status since the payment cannot be verified automatically. If, however, you are building a direct gateway, then you can complete the order here instead. Rather than using update_status when an order is paid, you should use payment_complete:

This ensures stock reductions are made, and the status is changed to the correct value.

If payment fails, you should throw an error and return null:

WooCommerce will catch this error and show it on the checkout page.

Updating order status and adding notes ↑ Back to top

Updating the order status can be done using functions in the order class. You should only do this if the order status is not processing (in which case you should use payment_complete()). An example of updating to a custom status would be:

The above example updates the status to On-Hold and adds a note informing the owner that it is awaiting a Cheque. You can add notes without updating the order status; this is used for adding a debug message:

Order status best practice ↑ Back to top

  • If the order has completed but the admin needs to manually verify payment, use On-Hold
  • If the order fails and has already been created, set to Failed
  • If payment is complete, let WooCommerce handle the status and use $order->payment_complete() . WooCommerce will use either Completedor Processingstatus and handle stock.

Notes on Direct Gateways ↑ Back to top

If you are creating an advanced, direct gateway (i.e., one that takes payment on the actual checkout page), there are additional steps involved. First, you need to set has_fields to true in the gateway constructor:

This tells the checkout to output a ‘payment_box’ containing your direct payment form that you define next.

Create a method called payment_fields() – this contains your form, most likely to have credit card details.

The next but optional method to add is validate_fields() . Return true if the form passes validation or false if it fails. You can use the wc_add_notice() function if you want to add an error and display it to the user.

Finally, you need to add payment code inside your process_payment( $order_id ) method. This takes the posted form data and attempts payment directly via the payment provider.

If payment fails, you should output an error and return nothing:

If payment is successful, you should set the order as paid and return the success array:

Working with Payment Gateway Callbacks (such as PayPal IPN) ↑ Back to top

If you are building a gateway that makes a callback to your store to tell you about the status of an order, you need to add code to handle this inside your gateway.

The best way to add a callback and callback handler is to use WC-API hooks. An example would be as PayPal Standard does. It sets the callback/IPN URL as:

Then hooks in its handler to the hook:

WooCommerce will call your gateway and run the action when the URL is called.

Hooks in Gateways ↑ Back to top

It’s important to note that adding hooks inside gateway classes may not trigger. Gateways are only loaded when needed, such as during checkout and on the settings page in admin.

You should keep hooks outside of the class or use WC-API if you need to hook into WordPress events from your class.

How WooCommerce Subscription works with Stripe Payment Gateway Plugin for WooCommerce?

Accept Stripe with WooCommerce Stripe Payment Gateway Plugin

Used by 3,000+WooCommerce Stores

#1in Customer Satisfaction

WebToffee Guarantee: Get Your Money Back if You Are Not Satisfied With The Product

There is no doubt that online business has moved to different verticals, and customers prefer diverse types of the online shopping experience. Subscription is one of them. There are various advantages of implementing subscriptions on your eCommerce store. For instance, from a business point of view, you can turn a single purchase into a guaranteed monthly (or as per your requirement) recurring revenues. This will also help you to project Customer Lifetime Value (CLV), which will eventually assist you in building a stronger relationship with your customers.

As Dan Barker, an eCommerce consultant, says…

One of the biggest advantage of subscription eCommerce is acquiring a transaction, (which) means, you acquire a customer over the longer term, rather than just that single one-off purchase.

From a customer’s perspective, subscriptions can benefit those with a small budget, to access enterprise software or products. This will also give them the flexibility to stop a service at any time, and there are a lot of other advantages based on different subscription business models.

As a matter of fact, one of the major concerns while implementing WooCommerce subscriptions service is finding a payment gateway that syncs suitably with your WooCommerce store. But, don’t be distressed!
Our WooCommerce Stripe payment gateway plugin works perfectly fine with WooCommerce subscription service.

This article intends to show you how our Stripe Payment Gateway Plugin for WooCommerceworks with WooCommerce subscription service. Refer the Stripe product page to know more about other various features of the plugin.

How to achieve WooCommerce Stripe Subscriptions?

Consider you have a WooCommerce store where you sell a monthly digest. Now, let us create a monthly subscription service for the digest.

For this demonstration, we will use the WooCommerce Subscriptionplugin.

Let us break down the whole process into foursimple steps:

1. Installing WooCommerce Subscription plugin

The first step is to install a subscription plugin. In our demonstration, the WooCommerce Subscriptionplugin. Purchase and install the plugin on your WooCommerce store. Refer to the product page for more information on the product.

A sample screenshot of the plugin settings is shown below.

2. Add new subscription product

Once the plugin is installed, we should add a new subscription product. Move to Dashboard > Products > Add newsection.Enter the product name, product description, and other related details.

Next, in the Product Datameta box, select your desired product type. This setting is the most important setting for creating a subscription product. In addition to the default product types, you can find two types of subscription products: Simple subscriptionand Variable subscription.

A sample screenshot is as shown below.

For our monthly digest, we can select Simple subscriptiontype. Further settings appear as shown in the screenshot below.

Let us set a subscription price of $10/monthfor a year, offer a free trial period of 10 days. Enter other details of the product and publish it.

3. Install our WooCommerce Stripe Payment Gateway Plugin

With our WooCommerce Stripe plugin, you can accept credit cards, Bitcoins, Alipayand Apple Paypayments on your WooCommerce store. You can capture payments, and perform full/partial refunds as well. Check out the complete list of features on its product page.

Once you have purchased and installed our WooCommerce Stripe plugin, read the product setting up article to understand the functionality of each feature of the plugin, and to configure it.

4. Subscribing the product

It’s time to purchase the product. For this, let us move to the front-end of our WooCommerce store.

A sample screenshot of the product page is shown below.

Moving to checkout page for purchasing the product. A screenshot of the checkout page is shown below.

Next, click on Pay via Stripebutton to proceed with the payment. Next, in the Stripe checkout form, enter the payment credentials, say credit card information to complete the payment transaction.

Viewing Subscriptions

Go to WooCommerce > Subscriptionsto view all subscription orders. Each subscription is indicated by the current status (ACTIVE – for successful payment/PENDING – for unsuccessful payments/ON HOLD – for pending manual payments), subscription number, total amount, start date, end date trial end, next payment and so on. In the same way, you can suspendor cancelthe subscription as well.

A sample screenshot of the Subscriptionspage is as shown below.

Changing the Payment Method

A separate section titled Subscriptionsis created for customers to view all their subscriptions, in their My Accountpage. If you have turned off automatic payments under Manual Renewal Paymentsoption in WooCommerce Subscription plugin settings, your customers can change the payment method from the subscription page. Read more about the subscription renewal process here.

A sample screenshot of a subscription order is shown below.

Click on Change Paymentto change the payment method. You can select from the available payment method, and proceed with the payment.

Therefore, in this way, you can achieveWooCommerce stripe subscriptionfor your WooCommerce store.

To know more about the product, check out Stripe Payment Gateway Plugin for WooCommerce.

For understanding each feature of the plugin, refer to the product setting up article.

Or check out the documentation section for more related articles.

Accept Stripe with WooCommerce Stripe Payment Gateway Plugin

Used by 3,000+WooCommerce Stores

#1in Customer Satisfaction

WebToffee Guarantee: Get Your Money Back if You Are Not Satisfied With The Product

How to Accept Payments With WordPress (2 Easy Options Explained)

by John Hughes

Looking to accept payments with WordPress? Whether you’re launching a full-on e-commerce store or just looking to list a few products or services for sale, WordPress has plenty of functionality to help you do just that.

Two of the best options to making that happen are WooCommerceand PayPal Buy Now Button– both are easy to set up and use and they provide two different levels of complexity to suit your unique needs.

In this article, we’ll guide you through the process of configuring both plugins to accept payments with WordPress.

If you just want a lightweight solution suitable for listing a small number of products or services, PayPal Buy Now Button is for you. And if you’d like a more complex and flexible solution, you might prefer going with WooCommerce. Either way, we’re going to show you how!

Introducing PayPal Buy Now Button

Current Version: 1.7.2

Last Updated: February 27, 2019

The PayPal Buy Now Button plugin is a straightforward tool to help you accept payments with WordPress. You can use it to insert a button – or several of them – anywhere on your site, and that button will enable users to pay you through PayPal. This plugin is incredibly simple to install, and configuring it shouldn’t take more than a few minutes.

Before we jump into the instructions, you may be interested to know that PayPal does enable you to add payment buttons manually, without the use of a plugin. You don’t need an account to do it either – just follow PayPal’s instructions and you’ll get a code snippet that you can add to a page or post.

If you’re wary about dealing with code, however, PayPal Buy Now Button is a solid alternative that also will save you some time if you need to create a large number of payment buttons. Read on to find out how to use it.

How to use PayPal Buy Now Button to accept online payments

After installing and activating the plugin, you’ll see a new PayPal Buttonoption under Settingson your dashboard. Clicking on this option will send you to the plugin’s main settings screen, where you can pick a language and currency for your button:

If you scroll a bit further down, you’ll find an option to enter your PayPal Merchant ID (a unique identifier for those of you who have merchant accounts) or a regular email address. You’ll need at least one of these to start receiving payments:

Finally, you can also pick from among several button styles at the bottom of this page, as well as indicate whether PayPal should open in the same window or a new one when a user clicks on the button.

After saving your settings, identify the page or post where you want to include your first PayPal button and open its editor. You’ll find a new PayPal Buttonoption right next to Add Media:

Click on it, and then all you have to do is indicate a name, price, and alignment for your button:

Once you’re done, click on Insertand the plugin will add a shortcode to your page. Your button will now show up on the front end of your site.

Easy as pie, right? If you’re looking for a more powerful option, however, read on to discover an excellent alternative you may want to try out.

Introducing WooCommerce

Current Version: 3.5.6

Last Updated: March 7, 2019

WooCommerce is one of the most popular e-commerce options for WordPress users, and with good reason. This plugin feels like a natural extension of WordPress right out of the box, and it packs all the features you’ll need to create and manage an online store. Plus, there are dozens of handy extensions available that can add extra functionality to your site.

The core difference between this one and the PayPal Buy Now Button pluginis that WooCommerce is a fully-fledged e-commerce store solution – it’s a complete online store. Whereas PayPal Buy Now Button is a simple buy button that only allows you to collect a payment for a specific thing, but is not connected with any online store functionality.

One of WooCommerce’s core features is, of course, accepting payments with WordPress. It enables customers to pay you using either PayPal or Stripe – as long as you turn those settings on – but it alsoprovides you with a way to add more choices. By using extensions, you can add integrate almost every major online payment gateway into your store. So if you’re looking for a plugin that lets you keep your options open, this is it.

Just as before, the first thing you’ll need to do is install and activate the plugin. When you’re done with that, proceed to the next section.

How to use WooCommerce to accept payments with WordPress

As soon as you activate WooCommerce, you’ll be taken to a setup wizard that will help you configure your online store from scratch. When you get to the fourth step, you’ll be able to choose the payment gateways you want to enable:

By default, WooCommerce ships with two popular payment gateways: PayPal and Stripe. You can configure each by navigating to WooCommerce → Settings → Checkouton your dashboard, and finding the corresponding option at the top of the screen:

For example, clicking on PayPalwill send you to a new page where you can configure where your payments will go, and customize all the other settings you’ll need:

The payment gateways you select will show up when a user tries to check out, so all you have to do is enable and configure each one. Then your store will be ready to go!

As we mentioned earlier, you can also use WooCommerce extensions to add more payment gateways to your roster. Setting these extensions up works just the same as with other WordPress plugins, and you can find them in the WooCommerce repository:

After enabling the extensions you want, you’ll see new options appear on your WooCommerce Settingspage. You can then configure them using the same method we described above. Then, your customers can pick which payment option they want to use on the front end of your site.

Once you set up your payment options, all you need to do is create WooCommerce products for the items that you want to sell.


Figuring out the best way to accept payments with WordPress shouldn’t be an afterthought to setting up your site; it’s a critical step to making sure your website succeeds. After all, customers will quickly become frustrated if they can’t pay with ease, and you won’t be able to focus on growing your site if you don’t get your money promptly.

  • If you’re looking for the easiest way to start accepting payments online, PayPal Buy Now Button may be the right plugin for you.
  • On the other hand, if you’d like to let your customers use more than one payment gateway, WooCommerce provides you with more alternatives (and comes with a lot of other excellent features that will help you set up your store).

Do you have any questions about how to accept payments with WordPress? Fire away in the comments section below!

Leave a Reply

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