id = 'checkout'; // @todo In future versions this may make more sense as 'payment' however to avoid breakage lets leave this alone until we refactor settings APIs in general. $this->label = _x( 'Payments', 'Settings tab label', 'woocommerce' ); add_action( 'woocommerce_admin_field_payment_gateways_banner', array( $this, 'payment_gateways_banner' ) ); add_action( 'woocommerce_admin_field_payment_gateways', array( $this, 'payment_gateways_setting' ) ); parent::__construct(); } /** * Get own sections. * * @return array */ protected function get_own_sections() { return array( '' => __( 'Payment methods', 'woocommerce' ), ); } /** * Get settings array. * * @return array */ protected function get_settings_for_default_section() { $settings = array( array( 'type' => 'title', // this is needed as tag is generated by this element, even if it has no other content. ), array( 'type' => 'payment_gateways_banner' ), // React mount point for embedded banner slotfill. array( 'type' => 'payment_gateways', ), array( 'type' => 'sectionend', 'id' => 'payment_gateways_options', ), ); return apply_filters( 'woocommerce_payment_gateways_settings', $settings ); } /** * Output the settings. */ public function output() { //phpcs:disable WordPress.Security.NonceVerification.Recommended global $current_section; // Load gateways so we can show any global options they may have. $payment_gateways = WC()->payment_gateways->payment_gateways(); if ( $current_section ) { foreach ( $payment_gateways as $gateway ) { if ( in_array( $current_section, array( $gateway->id, sanitize_title( get_class( $gateway ) ) ), true ) ) { if ( isset( $_GET['toggle_enabled'] ) ) { $enabled = $gateway->get_option( 'enabled' ); if ( $enabled ) { $gateway->settings['enabled'] = wc_string_to_bool( $enabled ) ? 'no' : 'yes'; } } $this->run_gateway_admin_options( $gateway ); break; } } } parent::output(); //phpcs:enable } /** * Run the 'admin_options' method on a given gateway. * This method exists to easy unit testing. * * @param object $gateway The gateway object to run the method on. */ protected function run_gateway_admin_options( $gateway ) { $gateway->admin_options(); } /** * Creates the React mount point for the embedded banner. */ public function payment_gateways_banner() { ?>
save_settings_for_current_section(); if ( ! $current_section ) { // If section is empty, we're on the main settings page. This makes sure 'gateway ordering' is saved. $wc_payment_gateways->process_admin_options(); $wc_payment_gateways->init(); } else { // There is a section - this may be a gateway or custom section. 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(); } } $this->do_update_options_action(); } } } return new WC_Settings_Payment_Gateways();
'', 'name' => __( 'Method', 'woocommerce' ), 'status' => __( 'Enabled', 'woocommerce' ), 'description' => __( 'Description', 'woocommerce' ), 'action' => '', ); $columns = apply_filters( 'woocommerce_payment_gateways_setting_columns', $default_columns ); foreach ( $columns as $key => $column ) { echo ''; } ?> payment_gateways->payment_gateways(); foreach ( $payment_gateways as $gateway ) { echo ''; foreach ( $columns as $key => $column ) { if ( ! array_key_exists( $key, $default_columns ) ) { do_action( 'woocommerce_payment_gateways_setting_column_' . $key, $gateway ); continue; } $width = ''; if ( in_array( $key, array( 'sort', 'status', 'action' ), true ) ) { $width = '1%'; } $method_title = $gateway->get_method_title() ? $gateway->get_method_title() : $gateway->get_title(); $custom_title = $gateway->get_title(); echo ''; } echo ''; } /** * Add "Other payment methods" link in WooCommerce -> Settings -> Payments * When the store is in WC Payments eligible country. * See https://github.com/woocommerce/woocommerce/issues/32130 for more details. */ if ( WooCommercePayments::is_supported() ) { $wcpay_setup = isset( $payment_gateways['woocommerce_payments'] ) && ! $payment_gateways['woocommerce_payments']->needs_setup(); $country = wc_get_base_location()['country']; $plugin_suggestions = Init::get_suggestions(); $active_plugins = PluginsHelper::get_active_plugin_slugs(); if ( $wcpay_setup ) { $link_text = __( 'Discover additional payment providers', 'woocommerce' ); $filter_by = 'category_additional'; } else { $link_text = __( 'Discover other payment providers', 'woocommerce' ); $filter_by = 'category_other'; } $plugin_suggestions = array_filter( $plugin_suggestions, function( $plugin ) use ( $country, $filter_by, $active_plugins ) { if ( ! isset( $plugin->{$filter_by} ) || ! isset( $plugin->image_72x72 ) || ! isset( $plugin->plugins[0] ) || in_array( $plugin->plugins[0], $active_plugins, true ) ) { return false; } return in_array( $country, $plugin->{$filter_by}, true ); } ); $columns_count = count( $columns ); $external_link_icon = ''; echo ''; // phpcs:ignore -- ignoring the error since the value is harded. echo "'; echo ''; } ?>
' . esc_html( $column ) . '
'; switch ( $key ) { case 'sort': ?>
id ) ) ) . '" class="wc-payment-gateway-method-title">' . wp_kses_post( $method_title ) . ''; if ( $method_title !== $custom_title ) { echo ' – ' . wp_kses_post( $custom_title ) . ''; } break; case 'description': echo wp_kses_post( $gateway->get_method_description() ); break; case 'action': if ( wc_string_to_bool( $gateway->enabled ) ) { /* Translators: %s Payment gateway name. */ echo '' . esc_html__( 'Manage', 'woocommerce' ) . ''; } else { if ( // Keep old brand name for backwards compatibility. ( 'WooCommerce Payments' === $method_title || 'WooPayments' === $method_title ) && class_exists( 'WC_Payments_Account' ) ) { $setup_url = WC_Payments_Account::get_connect_url(); } else { $setup_url = admin_url( 'admin.php?page=wc-settings&tab=checkout§ion=' . strtolower( $gateway->id ) ); } /* Translators: %s Payment gateway name. */ echo '' . esc_html__( 'Finish set up', 'woocommerce' ) . ''; } break; case 'status': echo ''; if ( wc_string_to_bool( $gateway->enabled ) ) { /* Translators: %s Payment gateway name. */ echo '' . esc_attr__( 'Yes', 'woocommerce' ) . ''; } else { /* Translators: %s Payment gateway name. */ echo '' . esc_attr__( 'No', 'woocommerce' ) . ''; } echo ''; break; } echo '
"; echo ""; // phpcs:ignore echo $link_text; // phpcs:ignore echo $external_link_icon; echo ''; if ( count( $plugin_suggestions ) ) { foreach ( $plugin_suggestions as $plugin_suggestion ) { $alt = str_replace( '.png', '', basename( $plugin_suggestion->image_72x72 ) ); // phpcs:ignore echo "{$alt}"; } echo '& more.'; } echo '