@@ -317,9 +317,9 @@ function( $acc, $zone ) {
317317 }
318318
319319 if ( $ is_block_editor && ! $ this ->asset_data_registry ->exists ( 'globalPaymentMethods ' ) ) {
320- $ payment_methods = WC ()-> payment_gateways -> payment_gateways ();
320+ $ payment_gateways = $ this -> get_enabled_payment_gateways ();
321321 $ formatted_payment_methods = array_reduce (
322- $ payment_methods ,
322+ $ payment_gateways ,
323323 function ( $ acc , $ method ) {
324324 if ( 'yes ' === $ method ->enabled ) {
325325 $ acc [] = [
@@ -348,6 +348,21 @@ function( $acc, $method ) {
348348 do_action ( 'woocommerce_blocks_checkout_enqueue_data ' );
349349 }
350350
351+ /**
352+ * Get payment methods that are enabled in settings.
353+ *
354+ * @return array
355+ */
356+ protected function get_enabled_payment_gateways () {
357+ $ payment_gateways = WC ()->payment_gateways ->payment_gateways ();
358+ return array_filter (
359+ $ payment_gateways ,
360+ function ( $ payment_gateway ) {
361+ return 'yes ' === $ payment_gateway ->enabled ;
362+ }
363+ );
364+ }
365+
351366 /**
352367 * Are we currently on the admin block editor screen?
353368 */
@@ -388,9 +403,23 @@ protected function hydrate_customer_payment_methods() {
388403 return ;
389404 }
390405 add_filter ( 'woocommerce_payment_methods_list_item ' , [ $ this , 'include_token_id_with_payment_methods ' ], 10 , 2 );
406+
407+ $ payment_gateways = $ this ->get_enabled_payment_gateways ();
408+ $ payment_methods = wc_get_customer_saved_methods_list ( get_current_user_id () );
409+
410+ // Filter out payment methods that are not enabled.
411+ foreach ( $ payment_methods as $ payment_method_group => $ saved_payment_methods ) {
412+ $ payment_methods [ $ payment_method_group ] = array_filter (
413+ $ saved_payment_methods ,
414+ function ( $ saved_payment_method ) use ( $ payment_gateways ) {
415+ return in_array ( $ saved_payment_method ['method ' ]['gateway ' ], array_keys ( $ payment_gateways ), true );
416+ }
417+ );
418+ }
419+
391420 $ this ->asset_data_registry ->add (
392421 'customerPaymentMethods ' ,
393- wc_get_customer_saved_methods_list ( get_current_user_id () )
422+ $ payment_methods
394423 );
395424 remove_filter ( 'woocommerce_payment_methods_list_item ' , [ $ this , 'include_token_id_with_payment_methods ' ], 10 , 2 );
396425 }
0 commit comments