2013-07-26 14:36:28 +00:00
< ? php
/**
2015-11-03 13:53:50 +00:00
* WooCommerce Shipping Settings
2013-07-26 14:36:28 +00:00
*
2015-12-09 17:11:59 +00:00
* @ author WooThemes
* @ category Admin
* @ package WooCommerce / Admin
* @ version 2.5 . 0
2013-07-26 14:36:28 +00:00
*/
2014-09-20 19:55:47 +00:00
if ( ! defined ( 'ABSPATH' ) ) {
2015-12-09 17:11:59 +00:00
exit ;
2014-09-20 19:55:47 +00:00
}
2013-07-26 14:36:28 +00:00
if ( ! class_exists ( 'WC_Settings_Payment_Gateways' ) ) :
/**
2015-11-03 13:31:20 +00:00
* WC_Settings_Payment_Gateways .
2013-07-26 14:36:28 +00:00
*/
class WC_Settings_Payment_Gateways extends WC_Settings_Page {
/**
* Constructor .
*/
public function __construct () {
2014-08-31 08:22:03 +00:00
2013-08-22 10:58:03 +00:00
$this -> id = 'checkout' ;
2014-02-06 15:44:50 +00:00
$this -> label = _x ( 'Checkout' , 'Settings tab label' , 'woocommerce' );
2013-07-26 14:36:28 +00:00
add_filter ( 'woocommerce_settings_tabs_array' , array ( $this , 'add_settings_page' ), 20 );
add_action ( 'woocommerce_sections_' . $this -> id , array ( $this , 'output_sections' ) );
add_action ( 'woocommerce_settings_' . $this -> id , array ( $this , 'output' ) );
add_action ( 'woocommerce_admin_field_payment_gateways' , array ( $this , 'payment_gateways_setting' ) );
add_action ( 'woocommerce_settings_save_' . $this -> id , array ( $this , 'save' ) );
}
/**
2015-11-03 13:31:20 +00:00
* Get sections .
2013-07-26 14:36:28 +00:00
*
* @ return array
*/
public function get_sections () {
$sections = array (
2015-01-23 13:05:35 +00:00
'' => __ ( 'Checkout Options' , 'woocommerce' )
2013-07-26 14:36:28 +00:00
);
2015-01-23 13:05:35 +00:00
if ( ! defined ( 'WC_INSTALLING' ) ) {
2015-12-09 17:11:59 +00:00
// Load shipping methods so we can show any global options they may have.
2015-01-23 13:05:35 +00:00
$payment_gateways = WC () -> payment_gateways -> payment_gateways ();
2013-07-26 14:36:28 +00:00
2015-01-23 13:05:35 +00:00
foreach ( $payment_gateways as $gateway ) {
$title = empty ( $gateway -> method_title ) ? ucfirst ( $gateway -> id ) : $gateway -> method_title ;
$sections [ strtolower ( get_class ( $gateway ) ) ] = esc_html ( $title );
}
2013-07-26 14:36:28 +00:00
}
2014-02-17 14:30:37 +00:00
return apply_filters ( 'woocommerce_get_sections_' . $this -> id , $sections );
2013-07-26 14:36:28 +00:00
}
/**
2015-11-03 13:31:20 +00:00
* Get settings array .
2013-07-26 14:36:28 +00:00
*
* @ return array
*/
public function get_settings () {
2014-09-12 11:20:06 +00:00
$settings = apply_filters ( 'woocommerce_payment_gateways_settings' , array (
2013-07-26 14:36:28 +00:00
2015-12-09 17:11:59 +00:00
array (
'title' => __ ( 'Checkout Process' , 'woocommerce' ),
'type' => 'title' ,
'id' => 'checkout_process_options' ,
),
2013-08-22 11:11:19 +00:00
array (
2015-03-24 15:51:53 +00:00
'title' => __ ( 'Coupons' , 'woocommerce' ),
'desc' => __ ( 'Enable the use of coupons' , 'woocommerce' ),
'id' => 'woocommerce_enable_coupons' ,
'default' => 'yes' ,
'type' => 'checkbox' ,
'checkboxgroup' => 'start' ,
'desc_tip' => __ ( 'Coupons can be applied from the cart and checkout pages.' , 'woocommerce' ),
),
array (
'desc' => __ ( 'Calculate coupon discounts sequentially' , 'woocommerce' ),
'id' => 'woocommerce_calc_discounts_sequentially' ,
'default' => 'no' ,
'type' => 'checkbox' ,
'desc_tip' => __ ( 'When applying multiple coupons, apply the first coupon to the full price and the second coupon to the discounted price and so on.' , 'woocommerce' ),
'checkboxgroup' => 'end' ,
2015-12-09 17:11:59 +00:00
'autoload' => false ,
2013-08-22 11:11:19 +00:00
),
array (
2016-01-05 11:23:15 +00:00
'title' => _x ( 'Checkout Process' , 'Settings group label' , 'woocommerce' ),
2014-08-31 08:22:03 +00:00
'desc' => __ ( 'Enable guest checkout' , 'woocommerce' ),
'desc_tip' => __ ( 'Allows customers to checkout without creating an account.' , 'woocommerce' ),
'id' => 'woocommerce_enable_guest_checkout' ,
'default' => 'yes' ,
'type' => 'checkbox' ,
'checkboxgroup' => 'start' ,
2015-12-09 17:11:59 +00:00
'autoload' => false ,
2013-08-22 11:11:19 +00:00
),
array (
2014-08-31 08:22:03 +00:00
'desc' => __ ( 'Force secure checkout' , 'woocommerce' ),
'id' => 'woocommerce_force_ssl_checkout' ,
'default' => 'no' ,
'type' => 'checkbox' ,
'checkboxgroup' => '' ,
2013-08-22 11:11:19 +00:00
'show_if_checked' => 'option' ,
2015-12-29 20:35:13 +00:00
'desc_tip' => __ ( 'Force SSL (HTTPS) on the checkout pages (an SSL Certificate is required).' , 'woocommerce' ),
2013-08-22 11:11:19 +00:00
),
2016-01-08 11:27:13 +00:00
'unforce_ssl_checkout' => array (
2014-08-31 08:22:03 +00:00
'desc' => __ ( 'Force HTTP when leaving the checkout' , 'woocommerce' ),
'id' => 'woocommerce_unforce_ssl_checkout' ,
'default' => 'no' ,
'type' => 'checkbox' ,
'checkboxgroup' => 'end' ,
2013-08-22 11:11:19 +00:00
'show_if_checked' => 'yes' ,
),
2015-12-09 17:11:59 +00:00
array (
'type' => 'sectionend' ,
'id' => 'checkout_process_options' ,
),
2013-08-22 11:11:19 +00:00
2015-12-09 17:11:59 +00:00
array (
'title' => __ ( 'Checkout Pages' , 'woocommerce' ),
'desc' => __ ( 'These pages need to be set so that WooCommerce knows where to send users to checkout.' , 'woocommerce' ),
'type' => 'title' ,
'id' => 'checkout_page_options' ,
),
2013-07-26 14:36:28 +00:00
array (
2014-08-31 08:22:03 +00:00
'title' => __ ( 'Cart Page' , 'woocommerce' ),
'desc' => __ ( 'Page contents:' , 'woocommerce' ) . ' [' . apply_filters ( 'woocommerce_cart_shortcode_tag' , 'woocommerce_cart' ) . ']' ,
'id' => 'woocommerce_cart_page_id' ,
'type' => 'single_select_page' ,
'default' => '' ,
2015-01-12 16:29:01 +00:00
'class' => 'wc-enhanced-select-nostd' ,
2014-08-31 08:22:03 +00:00
'css' => 'min-width:300px;' ,
'desc_tip' => true ,
2013-07-26 14:36:28 +00:00
),
2013-08-22 10:58:03 +00:00
array (
2014-08-31 08:22:03 +00:00
'title' => __ ( 'Checkout Page' , 'woocommerce' ),
'desc' => __ ( 'Page contents:' , 'woocommerce' ) . ' [' . apply_filters ( 'woocommerce_checkout_shortcode_tag' , 'woocommerce_checkout' ) . ']' ,
'id' => 'woocommerce_checkout_page_id' ,
'type' => 'single_select_page' ,
'default' => '' ,
2015-01-12 16:29:01 +00:00
'class' => 'wc-enhanced-select-nostd' ,
2014-08-31 08:22:03 +00:00
'css' => 'min-width:300px;' ,
'desc_tip' => true ,
2013-08-22 10:58:03 +00:00
),
array (
2014-08-31 08:22:03 +00:00
'title' => __ ( 'Terms and Conditions' , 'woocommerce' ),
'desc' => __ ( 'If you define a "Terms" page the customer will be asked if they accept them when checking out.' , 'woocommerce' ),
'id' => 'woocommerce_terms_page_id' ,
'default' => '' ,
2015-01-12 16:29:01 +00:00
'class' => 'wc-enhanced-select-nostd' ,
2014-08-31 08:22:03 +00:00
'css' => 'min-width:300px;' ,
'type' => 'single_select_page' ,
'desc_tip' => true ,
2015-12-09 17:11:59 +00:00
'autoload' => false ,
2013-08-22 10:58:03 +00:00
),
2015-12-09 17:11:59 +00:00
array (
'type' => 'sectionend' ,
'id' => 'checkout_page_options' ,
),
2013-08-22 10:58:03 +00:00
2013-08-22 11:11:19 +00:00
array ( 'title' => __ ( 'Checkout Endpoints' , 'woocommerce' ), 'type' => 'title' , 'desc' => __ ( 'Endpoints are appended to your page URLs to handle specific actions during the checkout process. They should be unique.' , 'woocommerce' ), 'id' => 'account_endpoint_options' ),
2013-08-22 10:58:03 +00:00
array (
2014-08-31 08:22:03 +00:00
'title' => __ ( 'Pay' , 'woocommerce' ),
'desc' => __ ( 'Endpoint for the Checkout → Pay page' , 'woocommerce' ),
'id' => 'woocommerce_checkout_pay_endpoint' ,
'type' => 'text' ,
'default' => 'order-pay' ,
'desc_tip' => true ,
2013-08-22 10:58:03 +00:00
),
array (
2014-08-31 08:22:03 +00:00
'title' => __ ( 'Order Received' , 'woocommerce' ),
'desc' => __ ( 'Endpoint for the Checkout → Order Received page' , 'woocommerce' ),
'id' => 'woocommerce_checkout_order_received_endpoint' ,
'type' => 'text' ,
'default' => 'order-received' ,
'desc_tip' => true ,
2013-08-22 10:58:03 +00:00
),
2013-11-01 17:08:22 +00:00
array (
'title' => __ ( 'Add Payment Method' , 'woocommerce' ),
'desc' => __ ( 'Endpoint for the Checkout → Add Payment Method page' , 'woocommerce' ),
2013-11-05 21:02:13 +00:00
'id' => 'woocommerce_myaccount_add_payment_method_endpoint' ,
2013-11-01 17:08:22 +00:00
'type' => 'text' ,
'default' => 'add-payment-method' ,
'desc_tip' => true ,
),
2015-12-09 17:11:59 +00:00
array (
'type' => 'sectionend' ,
'id' => 'checkout_endpoint_options' ,
),
2013-08-22 10:58:03 +00:00
2015-12-09 17:11:59 +00:00
array (
'title' => __ ( 'Payment Gateways' , 'woocommerce' ),
'desc' => __ ( 'Installed gateways are listed below. Drag and drop gateways to control their display order on the frontend.' , 'woocommerce' ),
'type' => 'title' ,
'id' => 'payment_gateways_options' ,
),
2013-08-22 10:58:03 +00:00
2015-12-09 17:11:59 +00:00
array (
'type' => 'payment_gateways' ,
),
2013-08-22 10:58:03 +00:00
2015-12-09 17:11:59 +00:00
array (
'type' => 'sectionend' ,
'id' => 'payment_gateways_options' ,
),
2013-07-26 14:36:28 +00:00
2014-09-12 11:20:06 +00:00
) );
2016-01-08 11:27:13 +00:00
if ( wc_site_is_https () ) {
unset ( $settings [ 'unforce_ssl_checkout' ] );
}
2014-09-12 11:20:06 +00:00
return apply_filters ( 'woocommerce_get_settings_' . $this -> id , $settings );
2013-07-26 14:36:28 +00:00
}
/**
2015-11-03 13:31:20 +00:00
* Output the settings .
2013-07-26 14:36:28 +00:00
*/
public function output () {
global $current_section ;
2015-12-09 17:11:59 +00:00
// Load shipping methods so we can show any global options they may have.
2013-07-26 14:36:28 +00:00
$payment_gateways = WC () -> payment_gateways -> payment_gateways ();
if ( $current_section ) {
2014-08-31 08:22:03 +00:00
2015-12-09 17:11:59 +00:00
foreach ( $payment_gateways as $gateway ) {
2014-08-31 08:22:03 +00:00
2013-08-08 11:38:20 +00:00
if ( strtolower ( get_class ( $gateway ) ) == strtolower ( $current_section ) ) {
2013-07-26 14:36:28 +00:00
$gateway -> admin_options ();
break ;
}
}
2015-12-09 17:11:59 +00:00
} else {
2013-07-26 14:36:28 +00:00
$settings = $this -> get_settings ();
WC_Admin_Settings :: output_fields ( $settings );
}
}
/**
* Output payment gateway settings .
*/
public function payment_gateways_setting () {
?>
< tr valign = " top " >
2014-08-15 09:28:34 +00:00
< th scope = " row " class = " titledesc " >< ? php _e ( 'Gateway Display Order' , 'woocommerce' ) ?> </th>
2015-12-09 17:11:59 +00:00
< td class = " forminp " >
2013-07-26 14:36:28 +00:00
< table class = " wc_gateways widefat " cellspacing = " 0 " >
< thead >
< tr >
< ? php
$columns = apply_filters ( 'woocommerce_payment_gateways_setting_columns' , array (
2015-04-13 14:32:54 +00:00
'sort' => '' ,
2013-09-09 16:15:58 +00:00
'name' => __ ( 'Gateway' , 'woocommerce' ),
'id' => __ ( 'Gateway ID' , 'woocommerce' ),
2015-04-13 14:32:54 +00:00
'status' => __ ( 'Enabled' , 'woocommerce' )
2013-07-26 14:36:28 +00:00
) );
foreach ( $columns as $key => $column ) {
echo '<th class="' . esc_attr ( $key ) . '">' . esc_html ( $column ) . '</th>' ;
}
?>
</ tr >
</ thead >
< tbody >
2014-08-31 08:22:03 +00:00
< ? php
foreach ( WC () -> payment_gateways -> payment_gateways () as $gateway ) {
2013-07-26 14:36:28 +00:00
2014-08-31 08:22:03 +00:00
echo '<tr>' ;
2013-07-26 14:36:28 +00:00
2014-08-31 08:22:03 +00:00
foreach ( $columns as $key => $column ) {
2013-07-26 14:36:28 +00:00
switch ( $key ) {
2014-08-31 08:22:03 +00:00
2015-04-13 14:32:54 +00:00
case 'sort' :
echo ' < td width = " 1% " class = " sort " >
2014-08-31 08:22:03 +00:00
< input type = " hidden " name = " gateway_order[] " value = " ' . esc_attr( $gateway->id ) . ' " />
</ td > ' ;
2015-12-09 17:11:59 +00:00
break ;
2014-08-31 08:22:03 +00:00
2013-09-09 16:15:58 +00:00
case 'name' :
2015-12-09 18:28:34 +00:00
$method_title = $gateway -> get_title () ? $gateway -> get_title () : __ ( '(no title)' , 'woocommerce' );
2013-09-09 16:15:58 +00:00
echo ' < td class = " name " >
2015-12-09 17:11:59 +00:00
< a href = " ' . admin_url( 'admin.php?page=wc-settings&tab=checkout§ion=' . strtolower( get_class( $gateway ) ) ) . ' " > ' . esc_html( $method_title ) . ' </ a >
2014-08-31 08:22:03 +00:00
</ td > ' ;
2015-12-09 17:11:59 +00:00
break ;
2014-08-31 08:22:03 +00:00
2013-09-09 16:15:58 +00:00
case 'id' :
2015-12-09 17:11:59 +00:00
echo '<td class="id">' . esc_html ( $gateway -> id ) . '</td>' ;
break ;
2014-08-31 08:22:03 +00:00
2013-07-26 14:36:28 +00:00
case 'status' :
echo '<td class="status">' ;
2014-08-31 08:22:03 +00:00
if ( $gateway -> enabled == 'yes' )
2015-04-13 14:32:54 +00:00
echo '<span class="status-enabled tips" data-tip="' . __ ( 'Yes' , 'woocommerce' ) . '">' . __ ( 'Yes' , 'woocommerce' ) . '</span>' ;
2014-08-31 08:22:03 +00:00
else
echo '-' ;
2013-07-26 14:36:28 +00:00
2014-08-31 08:22:03 +00:00
echo '</td>' ;
2015-12-09 17:11:59 +00:00
break ;
2014-08-31 08:22:03 +00:00
2013-07-26 14:36:28 +00:00
default :
do_action ( 'woocommerce_payment_gateways_setting_column_' . $key , $gateway );
2015-12-09 17:11:59 +00:00
break ;
2013-07-26 14:36:28 +00:00
}
}
echo '</tr>' ;
2014-08-31 08:22:03 +00:00
}
?>
2013-07-26 14:36:28 +00:00
</ tbody >
</ table >
</ td >
</ tr >
< ? php
}
/**
2015-11-03 13:31:20 +00:00
* Save settings .
2013-07-26 14:36:28 +00:00
*/
public function save () {
global $current_section ;
2015-05-29 16:38:25 +00:00
$wc_payment_gateways = WC_Payment_Gateways :: instance ();
2013-07-26 14:36:28 +00:00
2015-05-29 16:38:25 +00:00
if ( ! $current_section ) {
WC_Admin_Settings :: save_fields ( $this -> get_settings () );
$wc_payment_gateways -> process_admin_options ();
} else {
foreach ( $wc_payment_gateways -> payment_gateways () as $gateway ) {
if ( $current_section === sanitize_title ( get_class ( $gateway ) ) ) {
do_action ( 'woocommerce_update_options_payment_gateways_' . $gateway -> id );
$wc_payment_gateways -> init ();
}
}
2013-07-26 14:36:28 +00:00
}
}
}
endif ;
2014-08-31 08:22:03 +00:00
return new WC_Settings_Payment_Gateways ();