// Disable Woocommerce Payment Gateways for Specific Shipping Methods
add_filter( 'woocommerce_available_payment_gateways', 'wpsh_hide_payment_for_shipping', 10, 1 );

function wpsh_hide_payment_for_shipping( $available_gateways ) { 

    if ( ! ( is_checkout_pay_page() ) ) {
 	// Add your  paymente gateways you would like to disable
    $gateways_to_disable = array( 'woocommerce_payments' );
		
	// Set shipping methods		
    $shipping_methods = array( 'flexible_shipping_single:8', 'flexible_shipping_single:6');
    $disable_gateways = false;

    // Check if we need to disable gateways
    foreach ( $shipping_methods as $shipping_method ) {
        if ( strpos( WC()->session->get( 'chosen_shipping_methods' )[0], $shipping_method ) !== false ) $disable_gateways = true;
    }
    
    // If shipping mehtod is selected then the payment gateway will be disabled
    if ( $disable_gateways ) {
        foreach ( $available_gateways as $id => $gateway ) {
            if ( in_array( $id, $gateways_to_disable ) ) {
                unset( $available_gateways[$id] );
            }
        }
    }
    return $available_gateways;
}
else { return $available_gateways;
    }
}