Do you want to create a woocommerce payment gateway that allows custom payment options? This tutorial will briefly introduce how to create a payment gateway in woocommerce so that customers can make payment through this customized woocommerce payment gateway. You can create your own custom payment gateway. There are two ways to do this. You can use plug-ins or custom code. However, plug-ins can cause site bloat. That’s why we use custom code snippets.
Explain each step in detail so that beginners can use this method. How to create woocommerce payment gateway? This post creates a plug-in to add a new payment gateway. That is, this operation requires programming technology. Expand the woocommerce class. Woocommerce provides several core classes, such as payment gateway or email class. You can extend these classes and add unique functions to save development time. Also, make sure the plug-in works in a standard way. Wc_payment_gateway class wc_payment_gateway class extends it to provide specific structures and functions for payment methods, such as obtaining total order amount or audit page URL.
Extending this class can benefit from the structure. Handle certain functions, including obtaining titles and descriptions and displaying them on the payment page. Please note that all payment gateways of woocommerce start by extending the wc_payment_gateway class. The steps to follow include: 1. Check whether woocommerce is active. We will extend woocommerce class, so we need to check whether it is active\/\/ Make sure WooCommerce is active
if ( ! in_array( ‘woocommerce\/woocommerce.php’, apply_filters( ‘active_plugins’, get_option( ‘active_plugins’ ) ) ) ) return;
2. To build a child class, you must first wrap it as an initialization function, and then connect to plugins_load before the default priority.
Check whether woocommerce is active, and then load the class after the woocommerce core. This will be the second check for fatal errors. In addition, the wc_payment_gateway class is allowed. O to expand a class, follow the following format: The class my_child_class extension the_parent_class {} plugin displays:\/**
* Offline Payment Gateway
* @class WC_Gateway_Offline
* @extends WC_Payment_Gateway
* @version 1.0.0
* @package WooCommerce\/Classes\/Payment
* @author Njengah
*\/
add_action( ‘plugins_loaded’, ‘wc_offline_gateway_init’, 11 );
function wc_offline_gateway_init() {
class WC_Gateway_Offline extends WC_Payment_Gateway {
\/\/ You plugin code starts here
} \/\/ end \WC_Gateway_Offline class
}
3. Because there is an external class for gateway construction, the _construct() function must be built. This ensures that the variables that must be included in the class.
The required variables are as follows:$ this->id $this->ic
On $this – > has_fields = true or false (bool) $this – > method_title $this – > method_description after the variable is set, the generator needs several different functions. The form fields are set in the init_form_fields() function. This feature will add all setting fields, such as enabling gateway and adding title$ this->init_form_fields();
$this->init_settings();
4. Initialize form fields this section creates the init_form_fields() function to set the form fields of the payment gateway.
This function does nothing on the parent class, but if it is not redefined, it checks for fatal errors. However, we will provide some functionality in subclasses. The default fields that must be included are the title and description of the activity\/**
* Initialize Gateway Settings Form Fields
*\/
public function init_form_fields() {
$this->form_fields = apply_filters( ‘wc_offline_form_fields’, array(
‘enabled’ => array(
‘title’ => __( ‘Enable\/Disable’, ‘wc-gateway-offline’ ),
‘type’ => ‘checkbox’,
‘label’ => __( ‘Enable Offline Payment’, ‘wc-gateway-offline’ ),
‘default’ => ‘yes’
),
‘title’ => array(
‘title’ => __( ‘Title’, ‘wc-gateway-offline’ ),
‘type’ => ‘text’,
‘description’ => __( ‘This controls the title for the payment method the customer sees during checkout.’, ‘wc-gateway-offline’ ),
‘default’ => __( ‘Offline Payment’, ‘wc-gateway-offline’ ),
‘desc_tip’ => true,
),
‘description’ => array(
‘title’ => __( ‘Description’, ‘wc-gateway-offline’ ),
‘type’ => ‘textarea’,
‘description’ => __( ‘Payment method description that the customer will see on your checkout.’, ‘wc-gateway-offline’ ),
‘default’ => __( ‘Please remit payment to Store Name upon pickup or delivery.’, ‘wc-gateway-offline’ ),
‘desc_tip’ => true,
),
‘instructions’ => array(
‘title’ => __( ‘Instructions’, ‘wc-gateway-offline’ ),
‘type’ => ‘textarea’,
‘description’ => __( ‘Instructions that will be added to the thank you page and emails.’, ‘wc-gateway-offline’ ),
‘default’ => ”,
‘desc_tip’ => true,
),
) );
}
5. Payment processing is the most important part when generating a payment gateway. Woocommerce must be in what state and add the function of processing orders to inform customers where they will go after use.
public function process_payment( $order_id ) {
$order = wc_get
Method of adding page method of adding active navigation class based on URL method of deleting method payment button integrated by woocommerce and stoom method of woocommerce method of sending mpesa woocommerce payment method of woocommerce payment page method of hiding PayPal icon method of adding woocommerce payment icon on footer [HTML] How to change the PayPal icon on the woocomer payment page woocomer how to add a search on the shopping page woocomer how to add a wish list how to confirm the user’s login to WordPress how to delete the woocomer payment option from the payment woocomer how to delete the shopping basket when logging out How does woommerce change the exit endpoint