Payment Gateways – Page 2

Developing Decentralized Crypto Payment Gateway

Welcome to a detailed guide about setting up payments on the websites using cryptocurrency. First of all I will explain some basics to you and then we will create our own payment gateway for WooCommerce (it is a eCommerce platform for WordPress).

How to Validate Payment Gateway Settings Fields

It seems like my complete payment gateway tutorial is not that complete after all. I didn’t mention there how you can validate payment gateway admin options.

For example let’s assume that we have to validate a USDT address of a TRON network. Here is how it should work:

how to validate WooCommerce payment method settings

Let’s assume that we’ve already added a field for a USDT address inside init_form_fields() method. Just like that:

How to Get Payment Gateways Programmatically

Payment Complete Hooks

There are three different WooCommerce hooks after payment completed I would like to talk about.

  • woocommerce_pre_payment_complete,
  • woocommerce_payment_complete,
  • woocommerce_payment_complete_order_status_$status;

All of those hooks are fired when an order is either paid or doesn’t require a payment (Cash on Delivery for example). They also apply for custom payment gateways.

Change Specific Payment Gateway Title and Description

Change WooCommerce payment gateway title and description
In this example we change “Cash on delivery” payment gateway title and description. The code from this post applies to both “Checkout” and “Pay for order” pages.

Hide Payment Methods Based on Shipping Class in the Cart

As you probably know, shipping classes apply to every product individually.

What does it mean for us? It means that we have to loop through all the products in the cart in our code and check their shipping classes using either get_shipping_class() or get_shipping_class_id() methods.

WooCommerce product shipping classes
In this example I created a new shipping class “No PayPal” (in WooCommerce > Settings > Shipping > Shipping Classes), so if there are products in the cart with this shipping class we are going to deactivate PayPal payment gateway.

Also we have two options here – if any product in the cart has a specific shipping class or if all the products in the cart have the specific shipping class.

Redirect to a Different Thank You Page based on Payment Method

In this tutorial I will show how to perform a redirect to a custom order received paged depending on a payment gateway used by customer.