Below is a code snippet you can use to easily add SDI (Sistema di Interscambio) integration into WooCommerce, a WordPress plugin.
Below is a code snippet that you can use to easily add SDI (Sistema di Interscambio) integration to WooCommerce, a WordPress plugin.
/**
* Aggiungi lo SDI come metodo di pagamento in WooCommerce
*/
function aggiungi_sdi_metodo_pagamento($gateways) {
$gateways['sdi_gateway'] = 'WC_Gateway_SDI';
return $gateways;
}
add_filter('woocommerce_payment_gateways', 'aggiungi_sdi_metodo_pagamento');
/**
* Classe del gateway di pagamento SDI
*/
class WC_Gateway_SDI extends WC_Payment_Gateway {
/**
* Costruttore del gateway
*/
public function __construct() {
$this->id = 'sdi_gateway';
$this->icon = ''; // Inserisci l'URL dell'icona se necessario
$this->method_title = 'SDI';
$this->method_description = 'Pagamento tramite SDI';
$this->supports = array('products');
$this->init_form_fields();
$this->init_settings();
$this->title = $this->get_option('title');
$this->description = $this->get_option('description');
add_action('woocommerce_update_options_payment_gateways_' . $this->id, array($this, 'process_admin_options'));
}
/**
* Inizializza i campi di configurazione del gateway
*/
public function init_form_fields() {
$this->form_fields = array(
'enabled' => array(
'title' => 'Abilita/Disabilita',
'type' => 'checkbox',
'label' => 'Abilita pagamento tramite SDI',
'default' => 'yes',
),
'title' => array(
'title' => 'Titolo',
'type' => 'text',
'description' => 'Titolo del metodo di pagamento visualizzato durante il checkout',
'default' => 'SDI',
'desc_tip' => true,
),
'description' => array(
'title' => 'Descrizione',
'type' => 'textarea',
'description' => 'Descrizione del metodo di pagamento visualizzata durante il checkout',
'default' => 'Effettua il pagamento tramite SDI',
),
);
}
/**
* Processa il pagamento
*/
public function process_payment($order_id) {
$order = wc_get_order($order_id);
$order->update_status('on-hold', 'In attesa di pagamento tramite SDI');
$order->reduce_order_stock();
WC()->cart->empty_cart();
return array(
'result' => 'success',
'redirect' => $this->get_return_url($order),
);
}
}
Make sure to insert this code into the functions.php file of your theme or a custom plugin. Additionally, you will need to configure the SDI gateway settings through the WooCommerce administration.
Note: This code provides only a base for SDI integration in WooCommerce. You may need to make changes to adapt it to your specific needs, such as handling SDI responses and adding custom fields at checkout.
Pubblicato in WordPress
Be the first to comment