I have created a custom payment WooCommerce plugin. Once I activate my plugin its showing and accepting data in WooCommerce->Settings->Payments. But its not showing that plugin as payment gateway on checkout page.
When i go to settings->payment page it shows me my payment method and also accept my keys etc. But when i save details and move to checkout page its not showing any option their
I am waiting for a quick response and answer.
Please help me with it.
<?php
/*
* Plugin Name: Liberty Dollar Payment Gateway
* Plugin URI: https://libertydollar.nl
* Description: Introducing the Liberty Dollar Payment Gateway for WordPress, the ultimate solution for users looking to accept and make payments using Liberty Dollar balances directly on their WordPress websites.
* Author: Liberty Dollar Team
* Author URI: https://libertydollar.nl
* Version: 0.1.2
*/
add_action('plugins_loaded', 'liberty_init_class');
function liberty_init_class() {
// Check if WooCommerce is active
if ( ! class_exists( 'WooCommerce' ) ) {
// If WooCommerce is not active, bail out
return;
}
// Continue if WooCommerce is active
add_filter( 'woocommerce_payment_gateways', 'liberty_add_gateway_class' );
function liberty_add_gateway_class( $gateways ) {
$gateways[] = 'WC_Liberty_Gateway';
return $gateways;
}
class WC_Liberty_Gateway extends WC_Payment_Gateway {
public $testmode;
public $private_key;
public $publishable_key;
public function __construct() {
$this->id = 'libertydollar';
$this->icon = 'https://www.libertydollar.nl/static/media/ldfa-round-logo.76072dece7b030176311.png';
$this->has_fields = false;
$this->method_title = 'Liberty Dollar Payment Gateway';
$this->method_description = 'Description of Liberty Dollar payment gateway';
$this->init_form_fields();
$this->init_settings();
$this->title = $this->get_option( 'title' );
$this->description = $this->get_option( 'description' );
$this->enabled = $this->get_option( 'enabled' );
$this->testmode = 'yes' === $this->get_option( 'testmode' );
$this->private_key = $this->testmode ? $this->get_option( 'test_private_key' ) : $this->get_option( 'private_key' );
$this->publishable_key = $this->testmode ? $this->get_option( 'test_publishable_key' ) : $this->get_option( 'publishable_key' );
add_action( 'woocommerce_update_options_payment_gateways_' . $this->id, array( $this, 'process_admin_options' ) );
add_action( 'woocommerce_thankyou_' . $this->id, array( $this, 'thankyou_page' ) );
add_filter( 'woocommerce_payment_complete_order_status', array( $this, 'change_payment_complete_order_status' ), 10, 3 );
add_action( 'woocommerce_review_order_before_submit', array( $this, 'payment_fields' ) );
}
public function init_form_fields(){
$this->form_fields = array(
'enabled' => array(
'title' => 'Enable/Disable',
'label' => 'Enable Liberty Dollar Payment Gateway',
'type' => 'checkbox',
'description' => '',
'default' => 'no'
),
'title' => array(
'title' => 'Title',
'type' => 'text',
'description' => 'This controls the title which the user sees during checkout.',
'default' => 'Liberty Dollar Payment Gateway',
'desc_tip' => true,
),
'description' => array(
'title' => 'Description',
'type' => 'textarea',
'description' => 'This controls the description which the user sees during checkout.',
'default' => 'Pay with Liberty Dollar Wallet.',
),
'testmode' => array(
'title' => 'Test mode',
'label' => 'Enable Test Mode',
'type' => 'checkbox',
'description' => 'Place the payment gateway in test mode using test API keys.',
'default' => 'yes',
'desc_tip' => true,
),
'test_publishable_key' => array(
'title' => 'Test Publishable Key',
'type' => 'text'
),
'test_private_key' => array(
'title' => 'Test Private Key',
'type' => 'password',
),
'publishable_key' => array(
'title' => 'Live Publishable Key',
'type' => 'text'
),
'private_key' => array(
'title' => 'Live Private Key',
'type' => 'password'
)
);
}
public function payment_fields() {
echo '<div id="custom-payment-form">Pay Via LDFA</div>';
}
}
}
PhpXpert International is a new contributor to this site. Take care in asking for clarification, commenting, and answering.
Check out our Code of Conduct.