Skip to content

Commit

Permalink
Use hide_gateways_on_settings_page() to hide gateways from WooComme…
Browse files Browse the repository at this point in the history
…rce > Settings > Payment instead of CSS (#2937)

* Remove CSS to hide payment gateways

* Hide all legacy gateways from settings page

* Update includes/admin/class-wc-stripe-settings-controller.php

Co-authored-by: James Allan <james.allan@automattic.com>

---------

Co-authored-by: James Allan <james.allan@automattic.com>
  • Loading branch information
mattallan and james-allan committed Feb 26, 2024
1 parent 8f0db94 commit 46533c3
Show file tree
Hide file tree
Showing 8 changed files with 24 additions and 32 deletions.
1 change: 0 additions & 1 deletion assets/css/payment-methods-styles.css

This file was deleted.

1 change: 0 additions & 1 deletion assets/css/payment-methods-styles.css.map

This file was deleted.

15 changes: 0 additions & 15 deletions assets/css/payment-methods-styles.scss

This file was deleted.

2 changes: 1 addition & 1 deletion assets/js/stripe-payment-request.min.js

Large diffs are not rendered by default.

2 changes: 1 addition & 1 deletion assets/js/stripe.min.js

Large diffs are not rendered by default.

24 changes: 22 additions & 2 deletions includes/admin/class-wc-stripe-settings-controller.php
Original file line number Diff line number Diff line change
Expand Up @@ -142,9 +142,29 @@ public function admin_scripts( $hook_suffix ) {
* to display the payment gateways on the WooCommerce Settings page.
*/
public static function hide_gateways_on_settings_page() {
$gateways_to_hide = [
// Hide all UPE payment methods.
WC_Stripe_UPE_Payment_Method::class,
// Hide all legacy payment methods.
WC_Gateway_Stripe_Alipay::class,
WC_Gateway_Stripe_Sepa::class,
WC_Gateway_Stripe_Giropay::class,
WC_Gateway_Stripe_Ideal::class,
WC_Gateway_Stripe_Bancontact::class,
WC_Gateway_Stripe_Eps::class,
WC_Gateway_Stripe_P24::class,
WC_Gateway_Stripe_Boleto::class,
WC_Gateway_Stripe_Oxxo::class,
WC_Gateway_Stripe_Sofort::class,
WC_Gateway_Stripe_Multibanco::class,
];

foreach ( WC()->payment_gateways->payment_gateways as $index => $payment_gateway ) {
if ( $payment_gateway instanceof WC_Stripe_UPE_Payment_Method ) {
unset( WC()->payment_gateways->payment_gateways[ $index ] );
foreach ( $gateways_to_hide as $gateway_to_hide ) {
if ( $payment_gateway instanceof $gateway_to_hide ) {
unset( WC()->payment_gateways->payment_gateways[ $index ] );
break; // Break the inner loop as we've already found a match and removed the gateway
}
}
}
}
Expand Down
10 changes: 0 additions & 10 deletions includes/class-wc-gateway-stripe.php
Original file line number Diff line number Diff line change
Expand Up @@ -121,7 +121,6 @@ public function __construct() {
}

// Hooks.
add_action( 'admin_enqueue_scripts', [ $this, 'admin_scripts' ] );
add_action( 'wp_enqueue_scripts', [ $this, 'payment_scripts' ] );
add_action( 'woocommerce_update_options_payment_gateways_' . $this->id, [ $this, 'process_admin_options' ] );
add_action( 'woocommerce_admin_order_totals_after_total', [ $this, 'display_order_fee' ] );
Expand All @@ -140,15 +139,6 @@ public function __construct() {
add_action( 'admin_notices', [ $this, 'display_errors' ], 9999 );
}

/**
* Load admin scripts.
*/
public function admin_scripts() {
wp_register_style( 'payment-methods-styles', plugins_url( 'assets/css/payment-methods-styles.css', WC_STRIPE_MAIN_FILE ), [], WC_STRIPE_VERSION );
wp_enqueue_style( 'payment-methods-styles' );

}

/**
* Checks if gateway should be available to use.
*
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -185,7 +185,6 @@ public function __construct() {
}

add_action( 'woocommerce_update_options_payment_gateways_' . $this->id, [ $this, 'process_admin_options' ] );
add_action( 'admin_enqueue_scripts', [ $this, 'admin_scripts' ] );

// This is an ActionScheduler action.
add_action( self::UPDATE_SAVED_PAYMENT_METHOD, [ $this, 'update_saved_payment_method' ], 10, 2 );
Expand Down

0 comments on commit 46533c3

Please sign in to comment.