WC_Settings_Payment_Gateways

WC_Settings_Payment_Gateways.

Defined (1)

The class is defined in the following location(s).

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