2018-03-15 12:36:10 +00:00
|
|
|
<?php // @codingStandardsIgnoreLine.
|
2013-07-26 14:36:28 +00:00
|
|
|
/**
|
2018-03-15 12:36:10 +00:00
|
|
|
* WooCommerce Checkout Settings
|
2013-07-26 14:36:28 +00:00
|
|
|
*
|
2018-04-12 15:59:42 +00:00
|
|
|
* @package WooCommerce/Admin
|
2013-07-26 14:36:28 +00:00
|
|
|
*/
|
|
|
|
|
2018-03-15 12:36:10 +00:00
|
|
|
defined( 'ABSPATH' ) || exit;
|
|
|
|
|
|
|
|
if ( class_exists( 'WC_Settings_Payment_Gateways', false ) ) {
|
|
|
|
return new WC_Settings_Payment_Gateways();
|
2014-09-20 19:55:47 +00:00
|
|
|
}
|
2013-07-26 14:36:28 +00:00
|
|
|
|
2018-03-15 12:36:10 +00:00
|
|
|
/**
|
|
|
|
* WC_Settings_Payment_Gateways.
|
|
|
|
*/
|
|
|
|
class WC_Settings_Payment_Gateways extends WC_Settings_Page {
|
2013-07-26 14:36:28 +00:00
|
|
|
|
|
|
|
/**
|
2018-03-15 12:36:10 +00:00
|
|
|
* Constructor.
|
2013-07-26 14:36:28 +00:00
|
|
|
*/
|
2018-03-15 12:36:10 +00:00
|
|
|
public function __construct() {
|
|
|
|
$this->id = 'checkout';
|
2018-04-12 10:13:01 +00:00
|
|
|
$this->label = _x( 'Payments', 'Settings tab label', 'woocommerce' );
|
2013-07-26 14:36:28 +00:00
|
|
|
|
2018-03-15 12:36:10 +00:00
|
|
|
add_action( 'woocommerce_admin_field_payment_gateways', array( $this, 'payment_gateways_setting' ) );
|
|
|
|
parent::__construct();
|
|
|
|
}
|
2013-07-26 14:36:28 +00:00
|
|
|
|
2018-03-15 12:36:10 +00:00
|
|
|
/**
|
|
|
|
* Get sections.
|
|
|
|
*
|
|
|
|
* @return array
|
|
|
|
*/
|
|
|
|
public function get_sections() {
|
|
|
|
$sections = array(
|
2018-04-12 15:59:42 +00:00
|
|
|
'' => __( 'Payment methods', 'woocommerce' ),
|
2018-03-15 12:36:10 +00:00
|
|
|
);
|
|
|
|
return apply_filters( 'woocommerce_get_sections_' . $this->id, $sections );
|
|
|
|
}
|
2016-01-08 11:27:13 +00:00
|
|
|
|
2018-03-15 12:36:10 +00:00
|
|
|
/**
|
|
|
|
* Get settings array.
|
|
|
|
*
|
|
|
|
* @param string $current_section Section being shown.
|
|
|
|
* @return array
|
|
|
|
*/
|
|
|
|
public function get_settings( $current_section = '' ) {
|
|
|
|
$settings = array();
|
|
|
|
|
|
|
|
if ( '' === $current_section ) {
|
|
|
|
$settings = apply_filters(
|
|
|
|
'woocommerce_payment_gateways_settings', array(
|
|
|
|
array(
|
2018-04-12 15:59:42 +00:00
|
|
|
'title' => __( 'Payment methods', 'woocommerce' ),
|
|
|
|
'desc' => __( 'Installed payment methods are listed below. Drag and drop gateways to control their display order on the frontend.', 'woocommerce' ),
|
2018-03-15 12:36:10 +00:00
|
|
|
'type' => 'title',
|
|
|
|
'id' => 'payment_gateways_options',
|
|
|
|
),
|
|
|
|
|
|
|
|
array(
|
|
|
|
'type' => 'payment_gateways',
|
|
|
|
),
|
|
|
|
|
|
|
|
array(
|
|
|
|
'type' => 'sectionend',
|
|
|
|
'id' => 'payment_gateways_options',
|
|
|
|
),
|
|
|
|
)
|
|
|
|
);
|
2018-03-05 18:59:17 +00:00
|
|
|
}
|
2013-07-26 14:36:28 +00:00
|
|
|
|
2018-03-15 12:36:10 +00:00
|
|
|
return apply_filters( 'woocommerce_get_settings_' . $this->id, $settings, $current_section );
|
|
|
|
}
|
2013-07-26 14:36:28 +00:00
|
|
|
|
2018-03-15 12:36:10 +00:00
|
|
|
/**
|
|
|
|
* Output the settings.
|
|
|
|
*/
|
|
|
|
public function output() {
|
|
|
|
global $current_section;
|
2013-07-26 14:36:28 +00:00
|
|
|
|
2018-03-15 12:36:10 +00:00
|
|
|
// Load gateways so we can show any global options they may have.
|
|
|
|
$payment_gateways = WC()->payment_gateways->payment_gateways();
|
2013-07-26 14:36:28 +00:00
|
|
|
|
2018-03-15 12:36:10 +00:00
|
|
|
if ( $current_section ) {
|
|
|
|
foreach ( $payment_gateways as $gateway ) {
|
|
|
|
if ( in_array( $current_section, array( $gateway->id, sanitize_title( get_class( $gateway ) ) ), true ) ) {
|
2018-04-12 15:59:42 +00:00
|
|
|
if ( isset( $_GET['toggle_enabled'] ) ) { // WPCS: input var ok, CSRF ok.
|
|
|
|
$enabled = $gateway->get_option( 'enabled' );
|
|
|
|
|
|
|
|
if ( $enabled ) {
|
|
|
|
$gateway->settings['enabled'] = wc_string_to_bool( $enabled ) ? 'no' : 'yes';
|
|
|
|
}
|
|
|
|
}
|
2018-03-15 12:36:10 +00:00
|
|
|
$gateway->admin_options();
|
|
|
|
break;
|
|
|
|
}
|
2018-03-05 18:59:17 +00:00
|
|
|
}
|
2018-03-15 12:36:10 +00:00
|
|
|
} else {
|
|
|
|
$settings = $this->get_settings();
|
|
|
|
WC_Admin_Settings::output_fields( $settings );
|
2013-07-26 14:36:28 +00:00
|
|
|
}
|
2018-03-15 12:36:10 +00:00
|
|
|
}
|
2013-07-26 14:36:28 +00:00
|
|
|
|
2018-03-15 12:36:10 +00:00
|
|
|
/**
|
|
|
|
* Output payment gateway settings.
|
|
|
|
*/
|
|
|
|
public function payment_gateways_setting() {
|
|
|
|
?>
|
|
|
|
<tr valign="top">
|
2018-04-12 15:59:42 +00:00
|
|
|
<td class="wc_payment_gateways_wrapper" colspan="2">
|
2018-03-15 12:36:10 +00:00
|
|
|
<table class="wc_gateways widefat" cellspacing="0">
|
|
|
|
<thead>
|
|
|
|
<tr>
|
|
|
|
<?php
|
2018-04-12 15:59:42 +00:00
|
|
|
$default_columns = array(
|
|
|
|
'sort' => '',
|
|
|
|
'name' => __( 'Method', 'woocommerce' ),
|
|
|
|
'status' => __( 'Enabled', 'woocommerce' ),
|
|
|
|
'description' => __( 'Description', 'woocommerce' ),
|
|
|
|
'action' => '',
|
2018-03-15 12:36:10 +00:00
|
|
|
);
|
|
|
|
|
2018-04-12 15:59:42 +00:00
|
|
|
$columns = apply_filters( 'woocommerce_payment_gateways_setting_columns', $default_columns );
|
|
|
|
|
2018-03-15 12:36:10 +00:00
|
|
|
foreach ( $columns as $key => $column ) {
|
|
|
|
echo '<th class="' . esc_attr( $key ) . '">' . esc_html( $column ) . '</th>';
|
|
|
|
}
|
|
|
|
?>
|
|
|
|
</tr>
|
|
|
|
</thead>
|
|
|
|
<tbody>
|
|
|
|
<?php
|
|
|
|
foreach ( WC()->payment_gateways->payment_gateways() as $gateway ) {
|
|
|
|
|
2018-04-12 15:59:42 +00:00
|
|
|
echo '<tr data-gateway_id="' . esc_attr( $gateway->id ) . '">';
|
2013-07-26 14:36:28 +00:00
|
|
|
|
2018-03-05 18:59:17 +00:00
|
|
|
foreach ( $columns as $key => $column ) {
|
2018-04-12 15:59:42 +00:00
|
|
|
if ( ! array_key_exists( $key, $default_columns ) ) {
|
|
|
|
do_action( 'woocommerce_payment_gateways_setting_column_' . $key, $gateway );
|
|
|
|
continue;
|
|
|
|
}
|
2013-07-26 14:36:28 +00:00
|
|
|
|
2018-04-12 15:59:42 +00:00
|
|
|
$width = '';
|
|
|
|
|
|
|
|
if ( in_array( $key, array( 'sort', 'status', 'action' ), true ) ) {
|
|
|
|
$width = '1%';
|
|
|
|
}
|
|
|
|
|
|
|
|
echo '<td class="' . esc_attr( $key ) . '" width="' . esc_attr( $width ) . '">';
|
2018-03-15 12:36:10 +00:00
|
|
|
|
2018-04-12 15:59:42 +00:00
|
|
|
switch ( $key ) {
|
2018-03-15 12:36:10 +00:00
|
|
|
case 'sort':
|
2018-04-12 15:59:42 +00:00
|
|
|
echo '<input type="hidden" name="gateway_order[]" value="' . esc_attr( $gateway->id ) . '" />';
|
2018-03-15 12:36:10 +00:00
|
|
|
break;
|
|
|
|
case 'name':
|
|
|
|
$method_title = $gateway->get_title() ? $gateway->get_title() : __( '(no title)', 'woocommerce' );
|
2018-04-12 15:59:42 +00:00
|
|
|
echo '<a href="' . esc_url( admin_url( 'admin.php?page=wc-settings&tab=checkout§ion=' . strtolower( $gateway->id ) ) ) . '">' . esc_html( $method_title ) . '</a>';
|
2018-03-15 12:36:10 +00:00
|
|
|
break;
|
2018-04-12 15:59:42 +00:00
|
|
|
case 'description':
|
|
|
|
echo '<strong class="wc-payment-gateway-method-name">' . wp_kses_post( $gateway->get_method_title() ) . '</strong>';
|
|
|
|
echo wp_kses_post( $gateway->get_method_description() );
|
2018-03-15 12:36:10 +00:00
|
|
|
break;
|
2018-04-12 15:59:42 +00:00
|
|
|
case 'action':
|
|
|
|
if ( wc_string_to_bool( $gateway->enabled ) ) {
|
|
|
|
echo '<a class="button alignright" href="' . esc_url( admin_url( 'admin.php?page=wc-settings&tab=checkout§ion=' . strtolower( $gateway->id ) ) ) . '">' . esc_html__( 'Manage', 'woocommerce' ) . '</a>';
|
|
|
|
} else {
|
|
|
|
echo '<a class="button alignright" href="' . esc_url( admin_url( 'admin.php?page=wc-settings&tab=checkout§ion=' . strtolower( $gateway->id ) ) ) . '">' . esc_html__( 'Set up', 'woocommerce' ) . '</a>';
|
|
|
|
}
|
2018-03-15 12:36:10 +00:00
|
|
|
break;
|
2018-04-12 15:59:42 +00:00
|
|
|
case 'status':
|
|
|
|
echo '<a class="wc-payment-gateway-method-toggle-enabled" href="' . esc_url( admin_url( 'admin.php?page=wc-settings&tab=checkout§ion=' . strtolower( $gateway->id ) ) ) . '">';
|
|
|
|
if ( wc_string_to_bool( $gateway->enabled ) ) {
|
|
|
|
echo '<span class="woocommerce-input-toggle woocommerce-input-toggle--enabled">' . esc_attr__( 'Yes', 'woocommerce' ) . '</span>';
|
|
|
|
} else {
|
|
|
|
echo '<span class="woocommerce-input-toggle woocommerce-input-toggle--disabled">' . esc_attr__( 'No', 'woocommerce' ) . '</span>';
|
|
|
|
}
|
|
|
|
echo '</a>';
|
2018-03-15 12:36:10 +00:00
|
|
|
break;
|
|
|
|
}
|
2018-04-12 15:59:42 +00:00
|
|
|
|
|
|
|
echo '</td>';
|
2018-03-05 18:59:17 +00:00
|
|
|
}
|
2013-07-26 14:36:28 +00:00
|
|
|
|
2018-03-15 12:36:10 +00:00
|
|
|
echo '</tr>';
|
|
|
|
}
|
|
|
|
?>
|
|
|
|
</tbody>
|
|
|
|
</table>
|
|
|
|
</td>
|
|
|
|
</tr>
|
|
|
|
<?php
|
|
|
|
}
|
2013-07-26 14:36:28 +00:00
|
|
|
|
2018-03-15 12:36:10 +00:00
|
|
|
/**
|
|
|
|
* Save settings.
|
|
|
|
*/
|
|
|
|
public function save() {
|
|
|
|
global $current_section;
|
2013-07-26 14:36:28 +00:00
|
|
|
|
2018-03-15 12:36:10 +00:00
|
|
|
$wc_payment_gateways = WC_Payment_Gateways::instance();
|
2017-07-04 06:36:34 +00:00
|
|
|
|
2018-03-15 12:36:10 +00:00
|
|
|
if ( ! $current_section ) {
|
|
|
|
WC_Admin_Settings::save_fields( $this->get_settings() );
|
|
|
|
$wc_payment_gateways->process_admin_options();
|
2018-03-15 12:39:30 +00:00
|
|
|
$wc_payment_gateways->init();
|
2018-03-15 12:36:10 +00:00
|
|
|
} else {
|
|
|
|
foreach ( $wc_payment_gateways->payment_gateways() as $gateway ) {
|
|
|
|
if ( in_array( $current_section, array( $gateway->id, sanitize_title( get_class( $gateway ) ) ), true ) ) {
|
|
|
|
do_action( 'woocommerce_update_options_payment_gateways_' . $gateway->id );
|
|
|
|
$wc_payment_gateways->init();
|
2015-05-29 16:38:25 +00:00
|
|
|
}
|
|
|
|
}
|
2018-03-15 12:36:10 +00:00
|
|
|
}
|
2018-01-26 09:22:09 +00:00
|
|
|
|
2018-03-15 12:36:10 +00:00
|
|
|
if ( $current_section ) {
|
|
|
|
do_action( 'woocommerce_update_options_' . $this->id . '_' . $current_section );
|
2018-01-26 09:22:09 +00:00
|
|
|
}
|
2013-07-26 14:36:28 +00:00
|
|
|
}
|
2018-03-15 12:36:10 +00:00
|
|
|
}
|
2013-07-26 14:36:28 +00:00
|
|
|
|
2014-08-31 08:22:03 +00:00
|
|
|
return new WC_Settings_Payment_Gateways();
|