/includes/admin/settings/class-wc-settings-checkout.php

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