1 <?php
  2 /**
  3  * WooCommerce Shipping Settings
  4  *
  5  * @author      WooThemes
  6  * @category    Admin
  7  * @package     WooCommerce/Admin
  8  * @version     2.1.0
  9  */
 10 
 11 if ( ! defined( 'ABSPATH' ) ) exit; // Exit if accessed directly
 12 
 13 if ( ! class_exists( 'WC_Settings_Payment_Gateways' ) ) :
 14 
 15 /**
 16  * WC_Settings_Payment_Gateways
 17  */
 18 class WC_Settings_Payment_Gateways extends WC_Settings_Page {
 19 
 20     /**
 21      * Constructor.
 22      */
 23     public function __construct() {
 24         $this->id    = 'checkout';
 25         $this->label = _x( 'Checkout', 'Settings tab label', 'woocommerce' );
 26 
 27         add_filter( 'woocommerce_settings_tabs_array', array( $this, 'add_settings_page' ), 20 );
 28         add_action( 'woocommerce_sections_' . $this->id, array( $this, 'output_sections' ) );
 29         add_action( 'woocommerce_settings_' . $this->id, array( $this, 'output' ) );
 30         add_action( 'woocommerce_admin_field_payment_gateways', array( $this, 'payment_gateways_setting' ) );
 31         add_action( 'woocommerce_settings_save_' . $this->id, array( $this, 'save' ) );
 32     }
 33 
 34     /**
 35      * Get sections
 36      *
 37      * @return array
 38      */
 39     public function get_sections() {
 40         $sections = array(
 41             ''         => __( 'Checkout Options', 'woocommerce' )
 42         );
 43 
 44         // Load shipping methods so we can show any global options they may have
 45         $payment_gateways = WC()->payment_gateways->payment_gateways();
 46 
 47         foreach ( $payment_gateways as $gateway ) {
 48 
 49             $title = empty( $gateway->method_title ) ? ucfirst( $gateway->id ) : $gateway->method_title;
 50 
 51             $sections[ strtolower( get_class( $gateway ) ) ] = esc_html( $title );
 52         }
 53 
 54         return $sections;
 55     }
 56 
 57     /**
 58      * Get settings array
 59      *
 60      * @return array
 61      */
 62     public function get_settings() {
 63         return apply_filters( 'woocommerce_payment_gateways_settings', array(
 64 
 65             array(  'title' => __( 'Checkout Process', 'woocommerce' ), 'type' => 'title', 'id' => 'checkout_process_options' ),
 66 
 67             array(
 68                 'title' => __( 'Coupons', 'woocommerce' ),
 69                 'desc'          => __( 'Enable the use of coupons', 'woocommerce' ),
 70                 'id'            => 'woocommerce_enable_coupons',
 71                 'default'       => 'yes',
 72                 'type'          => 'checkbox',
 73                 'desc_tip'      =>  __( 'Coupons can be applied from the cart and checkout pages.', 'woocommerce' ),
 74                 'autoload'      => false
 75             ),
 76 
 77             array(
 78                 'title'     => _x( 'Checkout', 'Settings group label', 'woocommerce' ),
 79                 'desc'      => __( 'Enable guest checkout', 'woocommerce' ),
 80                 'desc_tip'  =>  __( 'Allows customers to checkout without creating an account.', 'woocommerce' ),
 81                 'id'        => 'woocommerce_enable_guest_checkout',
 82                 'default'   => 'yes',
 83                 'type'      => 'checkbox',
 84                 'checkboxgroup' => 'start',
 85                 'autoload'  => false
 86             ),
 87 
 88             array(
 89                 'desc'      => __( 'Force secure checkout', 'woocommerce' ),
 90                 'id'        => 'woocommerce_force_ssl_checkout',
 91                 'default'   => 'no',
 92                 'type'      => 'checkbox',
 93                 'checkboxgroup'     => '',
 94                 'show_if_checked' => 'option',
 95                 'desc_tip'  =>  __( 'Force SSL (HTTPS) on the checkout pages (an SSL Certificate is required).', 'woocommerce' ),
 96             ),
 97 
 98             array(
 99                 'desc'      => __( 'Un-force HTTPS when leaving the checkout', 'woocommerce' ),
100                 'id'        => 'woocommerce_unforce_ssl_checkout',
101                 'default'   => 'no',
102                 'type'      => 'checkbox',
103                 'checkboxgroup'     => 'end',
104                 'show_if_checked' => 'yes',
105             ),
106 
107             array( 'type' => 'sectionend', 'id' => 'checkout_process_options'),
108 
109             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' ),
110 
111             array(
112                 'title' => __( 'Cart Page', 'woocommerce' ),
113                 'desc'      => __( 'Page contents:', 'woocommerce' ) . ' [' . apply_filters( 'woocommerce_cart_shortcode_tag', 'woocommerce_cart' ) . ']',
114                 'id'        => 'woocommerce_cart_page_id',
115                 'type'      => 'single_select_page',
116                 'default'   => '',
117                 'class'     => 'chosen_select_nostd',
118                 'css'       => 'min-width:300px;',
119                 'desc_tip'  => true,
120             ),
121 
122             array(
123                 'title' => __( 'Checkout Page', 'woocommerce' ),
124                 'desc'      => __( 'Page contents:', 'woocommerce' ) . ' [' . apply_filters( 'woocommerce_checkout_shortcode_tag', 'woocommerce_checkout' ) . ']',
125                 'id'        => 'woocommerce_checkout_page_id',
126                 'type'      => 'single_select_page',
127                 'default'   => '',
128                 'class'     => 'chosen_select_nostd',
129                 'css'       => 'min-width:300px;',
130                 'desc_tip'  => true,
131             ),
132 
133             array(
134                 'title' => __( 'Terms and Conditions', 'woocommerce' ),
135                 'desc'      => __( 'If you define a "Terms" page the customer will be asked if they accept them when checking out.', 'woocommerce' ),
136                 'id'        => 'woocommerce_terms_page_id',
137                 'default'   => '',
138                 'class'     => 'chosen_select_nostd',
139                 'css'       => 'min-width:300px;',
140                 'type'      => 'single_select_page',
141                 'desc_tip'  => true,
142                 'autoload'  => false
143             ),
144 
145             array( 'type' => 'sectionend', 'id' => 'checkout_page_options' ),
146 
147             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' ),
148 
149             array(
150                 'title' => __( 'Pay', 'woocommerce' ),
151                 'desc'      => __( 'Endpoint for the Checkout &rarr; Pay page', 'woocommerce' ),
152                 'id'        => 'woocommerce_checkout_pay_endpoint',
153                 'type'      => 'text',
154                 'default'   => 'order-pay',
155                 'desc_tip'  => true,
156             ),
157 
158             array(
159                 'title' => __( 'Order Received', 'woocommerce' ),
160                 'desc'      => __( 'Endpoint for the Checkout &rarr; Order Received page', 'woocommerce' ),
161                 'id'        => 'woocommerce_checkout_order_received_endpoint',
162                 'type'      => 'text',
163                 'default'   => 'order-received',
164                 'desc_tip'  => true,
165             ),
166 
167             array(
168                 'title'    => __( 'Add Payment Method', 'woocommerce' ),
169                 'desc'     => __( 'Endpoint for the Checkout &rarr; Add Payment Method page', 'woocommerce' ),
170                 'id'       => 'woocommerce_myaccount_add_payment_method_endpoint',
171                 'type'     => 'text',
172                 'default'  => 'add-payment-method',
173                 'desc_tip' => true,
174             ),
175 
176             array( 'type' => 'sectionend', 'id' => 'checkout_endpoint_options' ),
177 
178             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' ),
179 
180             array( 'type' => 'payment_gateways' ),
181 
182             array( 'type' => 'sectionend', 'id' => 'payment_gateways_options' ),
183 
184         )); // End payment_gateway settings
185     }
186 
187     /**
188      * Output the settings
189      */
190     public function output() {
191         global $current_section;
192 
193         // Load shipping methods so we can show any global options they may have
194         $payment_gateways = WC()->payment_gateways->payment_gateways();
195 
196         if ( $current_section ) {
197             foreach ( $payment_gateways as $gateway ) {
198                 if ( strtolower( get_class( $gateway ) ) == strtolower( $current_section ) ) {
199                     $gateway->admin_options();
200                     break;
201                 }
202             }
203         } else {
204             $settings = $this->get_settings();
205 
206             WC_Admin_Settings::output_fields( $settings );
207         }
208     }
209 
210     /**
211      * Output payment gateway settings.
212      *
213      * @access public
214      * @return void
215      */
216     public function payment_gateways_setting() {
217         ?>
218         <tr valign="top">
219             <th scope="row" class="titledesc"><?php _e( 'Gateway Display', 'woocommerce' ) ?></th>
220             <td class="forminp">
221                 <table class="wc_gateways widefat" cellspacing="0">
222                     <thead>
223                         <tr>
224                             <?php
225                                 $columns = apply_filters( 'woocommerce_payment_gateways_setting_columns', array(
226                                     'default'  => __( 'Default', 'woocommerce' ),
227                                     'name'     => __( 'Gateway', 'woocommerce' ),
228                                     'id'       => __( 'Gateway ID', 'woocommerce' ),
229                                     'status'   => __( 'Status', 'woocommerce' ),
230                                     'settings' => ''
231                                 ) );
232 
233                                 foreach ( $columns as $key => $column ) {
234                                     echo '<th class="' . esc_attr( $key ) . '">' . esc_html( $column ) . '</th>';
235                                 }
236                             ?>
237                         </tr>
238                     </thead>
239                     <tbody>
240                         <?php
241                         $default_gateway = get_option( 'woocommerce_default_gateway' );
242 
243                         foreach ( WC()->payment_gateways->payment_gateways() as $gateway ) {
244 
245                             echo '<tr>';
246 
247                             foreach ( $columns as $key => $column ) {
248                                 switch ( $key ) {
249                                     case 'default' :
250                                         echo '<td width="1%" class="default">
251                                             <input type="radio" name="default_gateway" value="' . esc_attr( $gateway->id ) . '" ' . checked( $default_gateway, esc_attr( $gateway->id ), false ) . ' />
252                                             <input type="hidden" name="gateway_order[]" value="' . esc_attr( $gateway->id ) . '" />
253                                         </td>';
254                                     break;
255                                     case 'name' :
256                                         echo '<td class="name">
257                                             ' . $gateway->get_title() . '
258                                         </td>';
259                                     break;
260                                     case 'id' :
261                                         echo '<td class="id">
262                                             ' . esc_html( $gateway->id ) . '
263                                         </td>';
264                                     break;
265                                     case 'status' :
266                                         echo '<td class="status">';
267 
268                                         if ( $gateway->enabled == 'yes' )
269                                             echo '<span class="status-enabled tips" data-tip="' . __ ( 'Enabled', 'woocommerce' ) . '">' . __ ( 'Enabled', 'woocommerce' ) . '</span>';
270                                         else
271                                             echo '-';
272 
273                                         echo '</td>';
274                                     break;
275                                     case 'settings' :
276                                         echo '<td class="settings">
277                                             <a class="button" href="' . admin_url( 'admin.php?page=wc-settings&tab=checkout&section=' . strtolower( get_class( $gateway ) ) ) . '">' . __( 'Settings', 'woocommerce' ) . '</a>
278                                         </td>';
279                                     break;
280                                     default :
281                                         do_action( 'woocommerce_payment_gateways_setting_column_' . $key, $gateway );
282                                     break;
283                                 }
284                             }
285 
286                             echo '</tr>';
287                         }
288                         ?>
289                     </tbody>
290                 </table>
291             </td>
292         </tr>
293         <?php
294     }
295 
296     /**
297      * Save settings
298      */
299     public function save() {
300         global $current_section;
301 
302         if ( ! $current_section ) {
303 
304             $settings = $this->get_settings();
305 
306             WC_Admin_Settings::save_fields( $settings );
307             WC()->payment_gateways->process_admin_options();
308 
309         } elseif ( class_exists( $current_section ) ) {
310 
311             $current_section_class = new $current_section();
312 
313             do_action( 'woocommerce_update_options_payment_gateways_' . $current_section_class->id );
314 
315             WC()->payment_gateways()->init();
316         }
317     }
318 }
319 
320 endif;
321 
322 return new WC_Settings_Payment_Gateways();
WooCommerce API documentation generated by ApiGen 2.8.0